Hi,
I am using tomcat 4.0.3. I am playing with Datasources.
I am having trouble validating 'removing abandoned database pool
connections'.
I did the below:
-----------------------------------------------
1) I have set up the below parameters in my server.xml
<!-- configure your DBCP DataSource so that abandoned dB connections are
removed and recycled -->
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<!-- Use the removeAbandonedTimeout parameter to set the number of seconds a
dB connection has been idle before it is considered abandoned.
Default time is 300 seconds. Here we are choosing 60 seconds. -->
<parameter>
<name>removeAbandonedTimeout</name>
<value>20</value>
</parameter>
<!-- The logAbandoned parameter can be set to true if you want DBCP to log a
stack trace of the code which abandoned the dB connection resources.
Default is false. -->
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>
-----------------------------------------------
2) I modified my test program so that it does not close databse connection.
package foo;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class DBTest {
String foo = "Not Connected";
int bar = -1;
public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
Context envCtx = (Context) ctx.lookup("java:comp/env");
// Look up our data source
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Kranthi");
if (ds != null) {
Connection conn = ds.getConnection();
if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =
stmt.executeQuery(
"select id, foo, bar from testdata");
if(rst.next()) {
foo=rst.getString(2);
bar=rst.getInt(3);
}
/*stmt.close();
rst.close();
conn.close();
*/
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
----------------------------------------------------------------------------
--------------
I call the jsp that calls the above java program. But, its not actually
closing the open connections.
Can anybody please help me.
Thanks,
KYemula.