• Post Reply Bookmark Topic Watch Topic
  • New Topic

Database connection shouldnt be in Servlet?  RSS feed

 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using MVC for my Form and database web site.

I have my Database connections, SQL and prepared statements in my Helper classes and JavaBean classes.
I assume they shouldnt be in Servlet because that is where I am dispatching what page and where the user should be sent depending on what they entered. From my limited experience I assume I shouldnt have any database connections in my Controller Servlet?
[ November 05, 2007: Message edited by: Joseph Smithern ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All database activity should take place in the model which should be completely agnostic to the UI. So yes, no DB access in the controllers.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also consider using JNDI to get the data source for database instead of using driver manager to get the connection to database, if you are not doing it currently.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!