Question

I am working on an web application using servlet jsp. now I am planning to write all database activity(queries and prepared statements and their execution) in normal java class and instantiate those class in servlets. just for reusability. could you please suggest me if it's a good approach? I am using : tomcat6, servlet2.5 jsp2,mysql

Was it helpful?

Solution

Yes u can use a separate plain java class to acess database...thats what the MVC architecture is, your java file will behave as model that handles..data and db connectivity, while your Servlet will behave as controller, that calls your business code..which is in a separate reusable java file..

OTHER TIPS

If you are writing a web application accessing a DB, then I suggest that you use some Persistence API, such as JPA or Hibernate. if you are using Eclipse or another IDE, the ability to reverse engineer your Entities from the DB will save you a lot of errors and time.

See http://www.vogella.com/articles/JavaPersistenceAPI/article.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top