Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

J2EE Database Access ..

 
prasad agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to performance forum...
 
prasad agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So whats up guys ??

can i assume that this design is good enough? without requiring any changes
if so, thanks
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a similar thread.

http://www.coderanch.com/t/304631/JDBC/java/Request-critique-better-way-database

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 ]
 
prasad agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi steve ,

Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic