wood burning stoves 2.0*
The moose likes JSP and the fly likes Connection Pooling and JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Connection Pooling and JSTL" Watch "Connection Pooling and JSTL" New topic
Author

Connection Pooling and JSTL

Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
Hi Guys,
I am in the process of re-structuring most of my webapp and in particular will be using JSTL to get rid of all the scriptlets from JSPs and writing a new controller servlet as previously the app was using a Model 1 MVC. I am currently using a Connection Pool that came with Marty Hall's core Servlets book, which uses the Driver Manager (apparently no good if I want to use JSTL sql tags).
I need advice on the following please:
1) I have now been looking into using Apache DBCP, so that I can make use of connection pooling and use the JSTL sql tags. I would like to continue to specify the db details in my web.xml as opposed to per tag - can any one let me know what I need to do, a good article etc. I have searched JavaRanch and google but to no avail. I have downloaded the jar files from apache and looked at the samples.
2) Should I write my own controller servlet or use the Struts framework. From a learning point of view, I think it might be good to get familiar with struts but then what sort of learning curve is involved.
I look forward to hearing any points.
- FK


The secret to creativity is knowing how to hide your sources.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Rather than using a Pool Package, All containers that I know about that support JSP 1.2 support JNDI DataSource. Configure the DataSource in your container and use it.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
How do I release the connection pool when the servlet context is destroyed? I don't see a close() method in the DataSource interface.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
Thanks Carl for responding. I did since get some information on the subject and think it is making sense but have another question, I do need to read up now JNDI DataSource as not clear what it is for.
I was reading the following: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html on how to do what you have suggested. Is it a good practice to make application specific settings inside the server.xml, that is placing your username, password etc to the db inside the server.xml.
Ron, on the above link, I saw the following can be set:
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
Any connections that the application does not close are thus abondened will be closed by setting the above in server.xml.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
That's not what I'm referring to, though. When the ServletContext is destroyed, I want my Listener to close (destroy) the entire connection pool, thereby releasing all of the connections in it. But how do I do this with the DataSource interface?
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Datasource pools are gloabla to the Server. That means all webapps use the same one. If you could close it in one webapp, it would kill it for all the others as well. It gets cleaned up on server shutdown!
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
The database pool isn't global to the server if I declare it within a Context is, e.g.

This pool belongs only to the "budget" ServletContext, and is not accessible from any other webapp.
[ August 13, 2003: Message edited by: Ron Newman ]
[ August 13, 2003: Message edited by: Ron Newman ]
Niral Trivedi
Ranch Hand

Joined: Nov 26, 2001
Posts: 46
Ron,
Isn't creating destroying connection pool be handled by the application server itself? All the parameter we are specifying is the driver class name, username, password and data source name. Using these information, app server will manager creating and destroying pool based on context creation and destruction.
That makes me believe that when context is destroyed, app server will know that this context is destroyed and will also free up the pool associated with it.
Am I making sense or am I being stupid? Please have your opinion.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection Pooling and JSTL
 
Similar Threads
Implementing timeout in JSP
which one is better to use in project
Connection Pooling with Struts
which is better sql:query or DAO class
error: Communications link failure due to underlying exception