Is it true that the javax.sql.ConnectionEventListener is not supported
by the ClientConnectionPoolDatasource? The attached program does not
display the event messages when the network server is shutdown during
the application run. To view the problem:
1) start network server (I specified -noSecurityManager to eliminate
that added complexity)
2) run the program AND
when the following message is displayed, stop the Network Server
within 15 seconds:
* now kill the NS while I sleep for 15 secs*
The program will continue with the message: now try to use the
connection after you killed the nS
Only an exception is displayed:
Exception in thread "main" java.sql.SQLException: A network protocol
error was encountered and the connection has been terminated: the
requested command encountered an unarchitected and implementation
-specific condition for which there was no architected message
at
org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown
Source)
at
org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at
org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
at
org.apache.derby.client.am.LogicalConnection.prepareStatement(Unknown
Source)
at DerbyNotification.main(DerbyNotification.java:61)
Derby-941 lists the specifcation for both ConnectionEventListener and
StatementEventListener but it appears that only StatementEventListener
was implemented. If this is true are there plans to support
ConnectionEventListeners?
I hope I have just made a dumb error setting this up and someone can
correct me. Any assistance will be greatly appreciated.
Thank you, Stan
import java.sql.*;
import javax.sql.*;
import javax.sql.ConnectionEvent;
public class DerbyNotification implements javax.sql.ConnectionEventListener
{
public void connectionClosed(ConnectionEvent arg0)
{
System.out.println("Connection closed happened");
}
public void connectionErrorOccurred(ConnectionEvent arg0)
{
System.out.println("Connection error happened");
}
public static void main(String args[]) throws Exception
{
ConnectionEventListener listener = new DerbyNotification();
// org.apache.derby.jdbc.ClientConnectionPoolDataSource40 ds = new
org.apache.derby.jdbc.ClientConnectionPoolDataSource40();
org.apache.derby.jdbc.ClientConnectionPoolDataSource ds = new
org.apache.derby.jdbc.ClientConnectionPoolDataSource();
Connection conn = null;
ds.setDatabaseName("sampleDB;create=true");
PooledConnection pooledCon = ds.getPooledConnection();
conn = pooledCon.getConnection();
pooledCon.addConnectionEventListener(listener);
DatabaseMetaData md = conn.getMetaData();
System.out.println(md.getDatabaseProductVersion());
System.out.println(md.getDatabaseProductName());
System.out.println("got connection now sleep");
Statement st = null;
PreparedStatement ps1 = null;
st = conn.createStatement();
try
{
st.executeUpdate("drop table TAB1");
}
catch (SQLException x)
{
System.out.println("no table exists");
}
System.out.println("now kill the NS while I sleep for 15 secs");
Thread.sleep(15000);
System.out.println("now try to use the connection after you killed
the nS");
ps1 = conn.prepareStatement("CREATE TABLE TAB1(COL1 INT NOT NULL)");
ps1.executeUpdate();
conn.commit();
System.out.println("done");
}
}