aspose file tools
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

Win a copy of The Software Craftsman this week in the Agile forum!
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: 2764

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]
Have you tried LearnNowOnline?
subject: Accessing the DBlayer from Servlets