Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Pooling and JSTL

 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I release the connection pool when the servlet context is destroyed? I don't see a close() method in the DataSource interface.
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic