Hello,
I have a DB2 v7.2 server running on a Linux machine and a Java client on
another linux machine.
I'm using pooled connection. I have implemented my own
ConnectionEventListener, I register it onto each PoolConnection I obtain
from the JDBC driver, but the problem is that this listener is never called.
At the end of this mail, I attach the Java code I use for testing this problem.
Here is the output of this Java code.
Product name: DB2/LINUX
Product version: 07.02.0000
Driver name: IBM DB2 JDBC 2.0 Type 3
Driver version: 07.02.0000
Is it a know problem ? Do you have a solution for this problem ? I need to be
notified when a connection is closed to manage my connection pool...
Any help is appreciated... Thanks in advance,
Jacques-Olivier Haenni
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DatabaseMetaData;
import javax.sql.ConnectionEventListener;
import javax.sql.PooledConnection;
import javax.sql.ConnectionEvent;
import COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource;
public class DB2Pooling implements ConnectionEventListener {
private static final String DB_NAME = "leaf2";
private static final String DB_SERVER = "leaffy";
private static final String DB_USER = "db2leaf";
private static final String DB_PASSWORD = "leafdb2";
public static void main(String[] args) throws SQLException {
new DB2Pooling().test();
}
public void test() throws SQLException {
DB2ConnectionPoolDataSource db2ConnectionPoolDataSource
= new DB2ConnectionPoolDataSource();
db2ConnectionPoolDataSource.setDatabaseName(DB_NAM E);
db2ConnectionPoolDataSource.setServerName(DB_SERVE R);
PooledConnection pc
= db2ConnectionPoolDataSource.getPooledConnection(DB _USER,
DB_PASSWORD);
pc.addConnectionEventListener(this);
Connection c = pc.getConnection();
DatabaseMetaData metaData = c.getMetaData();
System.out.println("Product name: "
+ metaData.getDatabaseProductName());
System.out.println("Product version: "
+ metaData.getDatabaseProductVersion());
System.out.println("Driver name: "
+ metaData.getDriverName());
System.out.println("Driver version: "
+ metaData.getDriverVersion());
c.close();
try {
java.lang.Thread.sleep(5000);
} catch (InterruptedException ie) {
}
}
public void connectionClosed(ConnectionEvent event) {
System.out.println("connectionClosed method called.");
}
public void connectionErrorOccurred(ConnectionEvent event) {
System.out.println("connectionClosed method called.");
}
}