Title: Connection to database from jsp.

We have a system consisting of a group of jsps - which have links to one another. There is no controller servlet as it is a simple system. What i want is to access the database from the jsps. The problem is that I do not want a new connection to be established everytime a request is made. What is the solution for this?

I had initially thought of having a utility class and in that I can have a getConnection method which returns the connection to a static connection reference in the same utility class. This can then be assigned to the jsps (by making a call from the jsps to some method - returnConn, in the utilily class). Is it true that a new connection will be established everytime. This has confused me a bit.

I am infact confused now about the very concept of static references. How do you think this problem can be solved? Will a servlet be of any use? Actually in a servlet, if we have a static connection reference as a class variable, and the initialization is done ( acquiring a connection) in the init method ( as init is executed only once in the lifetime of a servlet), the problem may be solved. In a servlet, the init method is executed only once and the servlet does not go out of memory till the server comes down. So I presume the connection will also be the same. Is this correct? Even if it is, I want to avoid the servlet, as it will be a lot of rework if the servlet has to be fit in. The application would have to be changed. Suggestions invited.


Anoop Kumar V.


Reply via email to