Frage

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

War es hilfreich?

Lösung

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..

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top