Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes Accessing the DBlayer from Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing the DBlayer from Servlets" Watch "Accessing the DBlayer from Servlets" New topic

Accessing the DBlayer from Servlets

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
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

Joined: Jun 06, 2007
Posts: 2851

All you need to do is to read about the Data Access Object design pattern and decide for yourself.

Hope this helps

|Asking Good Questions|
abani patra
Ranch Hand

Joined: Oct 11, 2011
Posts: 70
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]
wood burning stoves
subject: Accessing the DBlayer from Servlets
It's not a secret anymore!