Hello,
I have been using the MySQL connector with the C3P0 connection pool for
several months. I have C3P0 configured to use the MysqlConnectionTester
to detect dead connections. According to several sources, this is more
efficient than performing a query against the database. For my
purposes, this configuration has been working as expected.
I recently upgraded C3P0 to version 0.9.1 and found that the
MysqlConnectionTester began throwing ClassCastExceptions. A quick debug
session revealed that C3P0 had begun passing Mysql JDBC connections to
the tester, where before it had provided C3P0 proxy connections. This
change is present in subsequent releases of C3P0, and appears to have
been made for efficiency reasons.
The attached patch accounts for this change, and maintains compatibility
with C3P0's previous behavior. The patch applies to version 5.0.6 and
3.1.14 of the Mysql Java connector source.
Please let me know if this issue has already been addressed, or if there
is anything else I can do to get this change incorporated into a future
release.
Thank you,
~brian skrab
Epok, Incorporated
http://www.epok.net/
diff -urN src.orig/com/mysql/jdbc/integration/c3p0/MysqlConnectionTester.java
src/com/mysql/jdbc/integration/c3p0/MysqlConnectionTester.java
--- src.orig/com/mysql/jdbc/integration/c3p0/MysqlConnectionTester.java Tue May 15
13:37:59 2007
+++ src/com/mysql/jdbc/integration/c3p0/MysqlConnectionTester.java Wed Jun 6 12:25:42
2007
@@ -65,13 +65,20 @@
* @see com.mchange.v2.c3p0.ConnectionTester#activeCheckConnection(java.sql.Connection)
*/
public int activeCheckConnection(Connection con) {
- C3P0ProxyConnection castCon = (C3P0ProxyConnection) con;
-
try {
if (pingMethod != null) {
- castCon.rawConnectionOperation(pingMethod,
- C3P0ProxyConnection.RAW_CONNECTION, NO_ARGS_ARRAY);
+ if (con instanceof com.mysql.jdbc.Connection) {
+ // We've been passed an instance of a MySQL connection --
+ // no need for reflection
+ ((com.mysql.jdbc.Connection) con).ping();
+ } else {
+ // Assume the connection is a C3P0 proxy
+ C3P0ProxyConnection castCon = (C3P0ProxyConnection) con;
+ castCon.rawConnectionOperation(pingMethod,
+ C3P0ProxyConnection.RAW_CONNECTION, NO_ARGS_ARRAY);
+ }
} else {
+ // No driver-specific test method
Statement pingStatement = null;
try {