Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing the DBlayer from Servlets

 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi with the intention of keeping my DB layer separate from my servlets. I decided to create a separate class which connected to the DB
the class is as follows:



Now the servlet connects to this class and gets a result set which it packages in a bean and sends it to the jsp for displaying in a grid.
I read the best way to send the data of a result set is via beans. please correct me if i am wrong..
so my servlet code is something like this



Now I wanted the opinions of the experts out there is this the right directions ?? Could i make any improvements ?? Any suggestions ??

 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you need to do is to read about the Data Access Object design pattern and decide for yourself.

Hope this helps
 
abani patra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to suggest used a static method inside your external class to retrieve the connection and rest if still you want to in other palace user another service class where used the static method and other parameter to give the result back to the Servlet.

[Edited to remove useless link]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic