File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing the DBlayer from Servlets" Watch "Accessing the DBlayer from Servlets" New topic
Author

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
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

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

Hope this helps


SCJP, SCWCD.
|Asking Good Questions|
abani patra
Ranch Hand

Joined: Oct 11, 2011
Posts: 70
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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Accessing the DBlayer from Servlets
 
Similar Threads
Unable to find specific product
basic JDBC application
MS Access NullPointerException
Tomcat - MySql - Win98 Jdbc connection = BOOM!
JDBC return null when called from a servlet