File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes J2EE Database Access .. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "J2EE Database Access .." Watch "J2EE Database Access .." New topic

J2EE Database Access ..

prasad agarwal
Ranch Hand

Joined: Aug 24, 2006
Posts: 67
Hi all,..

Well this thread is just to discuss about efficient ways of accessing Database
from your J2ee applications.. I really want to hear from you guys

I am not using EJB or Hibernate at this moment..

This is what i am presently doing:

In web.xml i declare the JNDI DataSource name as a context-param

and then in ServletContextListener i perform a JNDI DataSource lookup
and store the datasource instance in ServletContext scope

Then in each servlet, i get the instance of DataSource name, make a connection,
perform SQL queries and close the connection

Now talking about how i perform SQL queries, i have another POJO class (Plain old java Object)
many queries as many methods in one POJO class .. As an example...

I create an Object of the POJO class and call these methods from the Servlet.
I am not saying anything wrong going on, but i just want to hear comments from you guys.

Any flaw?? What would be the best way to perform Database access - and perform SQL queries
in a J2EE web application ..?? Any improvements or changes i have to do ??

Thanks again
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

Moved to performance forum...

[OCA 8 Book] [Blog]
prasad agarwal
Ranch Hand

Joined: Aug 24, 2006
Posts: 67
So whats up guys ??

can i assume that this design is good enough? without requiring any changes
if so, thanks
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
Here is a similar thread.

Also, I wouldn't handle connections in the servlet. Hide the connections from the front end. Being as you are returning an ArrayList and not a ResultSet this should be easy enough to do.
[ September 20, 2006: Message edited by: steve souza ] - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
prasad agarwal
Ranch Hand

Joined: Aug 24, 2006
Posts: 67
Hi steve ,

Thanks a lot
I agree. Here's the link:
subject: J2EE Database Access ..
jQuery in Action, 3rd edition