JNDI Lookup in Servlet - Design Question
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ashish_Gupta
Posted On:   Wednesday, October 12, 2005 11:02 PM

I will appreciate if someone answers/clarifies my following questions. I am using Tomcat Connection pooling. 1. If I understand correctly- with Connection Pooling - Server will take care of opening the connections with DB So if the Max users allowed is 10, it means that at any given time 10 Concurrent users will be allowed access to DB. 2. Where do I place the code for doing the context lookup? I have many servlets called by JSP pages and these servlets will be accessing Database. 2 (a) Shall I place the context lookup code in each of the servlets Init Method, but by doing so I am writing the same code again and again. If I understand cor   More>>

I will appreciate if someone answers/clarifies my following questions.
I am using Tomcat Connection pooling.

1. If I understand correctly- with Connection Pooling - Server will take care of opening the connections with DB
So if the Max users allowed is 10, it means that at any given time 10 Concurrent users will be allowed access to DB.


2. Where do I place the code for doing the context lookup?
I have many servlets called by JSP pages and these
servlets will be accessing Database.



2 (a) Shall I place the context lookup code in each of
the servlets Init Method,
but by doing so I am writing the same code again and
again.

If I understand correctly the Context lookup code is
following 3 lines or Can I squeeze more code in Init()

Context i = new InitialContext();
Context e = (Context) i.lookup("java:comp/env");
DataSource d = (DataSource) e.lookup("jdbc/mytestdb");


Again if I have 30 Servlets, is this still a good idea?


2. (b) If there is an alternative to 2 (a), like having
another class or something, please elaborate on that
and which part of code should be in this alternative.



My application will be using JSP pages to call servlets that access Database to update or display results.



I have read about DB helper classes, but not quite understood it well.


Thank you very much.

   <<Less

Re: JNDI Lookup in Servlet - Design Question

Posted By:   Vijendra_Singh  
Posted On:   Wednesday, November 30, 2005 06:58 AM

I think u should take help of patterns.First try to understand how patterns works.
Then create a class for doing lookup and establishing the connection.The same connection you call everywhere(in all locations).

You can go like creating a interface implementing it in abstratc class .ultimately creating connection.
calling this connection object where ever you require later.

All the best.

Vj
About | Sitemap | Contact