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

有帮助吗?

解决方案

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top