You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Charles P. Killmer" <ch...@netgaintechnology.com> on 2005/05/23 18:43:25 UTC

DBCP

Supposing I forgot to close a database connection.  And the script was
requested numerous times.  And now my scripts can not get any database
connections.  Is there a way to close those connections without
restarting Tomcat?
 
Charles

RE: DBCP

Posted by Steve Kirk <to...@web-startup.co.uk>.
DBCP has some config params in the context.xml that will clean up for you if
you don't return resources to the pool.  It will also test connections for
you to make sure they're alive, and close/replace them if not.  To config
these features, set the params in your <Context>'s DBCP <Resource> tag, for
example:

	<Resource name="jdbc/myDbResource" auth="Container"
type="javax.sql.DataSource" 
		maxActive="10" maxIdle="5" maxWait="10000" 
		username="ao" password="ao"
driverClassName="com.mysql.jdbc.Driver" 
		url="jdbc:mysql://localhost:3306/myWebApp"
		
		removeAbandoned="true" 
		removeAbandonedTimeout="60" 
		logAbandoned="true" 
		validationQuery="select 1"
		testOnBorrow="true"
		testWhileIdle="true"
		timeBetweenEvictionRunsMillis="10000"
		minEvictableIdleTimeMillis="60000"
	/>

The attributes in question are those from removeAbandoned down.

However it is not advised to rely on this as a means of managing your pool -
this is your safety net.  It's far better to return connections to the pool
yourself in the first place.  A proper try/catch/finally structure is the
way to go, there are numerous examples on the web.

You don't mention your TC version but a good starting poing in the docs for
the latest version (5.5.x) are here: 
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-how
to.html 

Read the whole page, and for a decent try/catch/finally code example, focus
on the code in the section "Random Connection Closed Exceptions".

> -----Original Message-----
> From: Charles P. Killmer [mailto:charlesk@netgaintechnology.com] 
> Sent: Monday 23 May 2005 17:43
> To: Tomcat Users List
> Subject: DBCP
> 
> 
> Supposing I forgot to close a database connection.  And the script was
> requested numerous times.  And now my scripts can not get any database
> connections.  Is there a way to close those connections without
> restarting Tomcat?
>  
> Charles
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org