This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
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: 3748

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 ..
It's not a secret anymore!