Bug #64480 Sometimes retrieving a Connection using the Connector/J mysql driver fails
Submitted: 28 Feb 2012 9:53 Modified: 13 Mar 2012 16:12
Reporter: Tim Lammens Email Updates:
Status: Closed Impact on me:
Category:Connector / J Severity:S1 (Critical)
Version:5.1.18 OS:Linux
Assigned to: CPU Architecture:Any

[28 Feb 2012 9:53] Tim Lammens
Using the latest (5.1.18) mysql driver for Java the following exception happens when retrieving a Connection object.
A SQL exception is thrown inside the driver even before executing a query. Inside the driver "SHOW VARIABLES" is executed and retrieving this result throws the Exception.

Mysqld version:
mysqld  Ver 4.0.24_Debian-10sarge1-log for pc-linux-gnu on i386 (Source distribution)

java.sql.SQLException: ResultSet is from UPDATE. No Data.
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
        at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:7152)
        at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3870)
        at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3407)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2384)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
        at sun.reflect.GeneratedConstructorAccessor12.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
        at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:440)
        at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:138)
        at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:108)
        at com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource.getPooledConnection(MysqlConnectionPoolDataSource.java:59)
        at biz.source_code.miniConnectionPoolManager.MiniConnectionPoolManager.getConnection3(MiniConnectionPoolManager.java:182)
        at biz.source_code.miniConnectionPoolManager.MiniConnectionPoolManager.getConnection2(MiniConnectionPoolManager.java:164)
        at biz.source_code.miniConnectionPoolManager.MiniConnectionPoolManager.getConnection(MiniConnectionPoolManager.java:145)

How to repeat:
Create a connection pool using a miniconnectionpool manager:

Sometimes retrieving a Connection throws a SQL Exception even before a query is executed. There seems to be a problem within the driver when executing a "SHOW VARIABLES" query.

Mysqld version:
mysqld  Ver 4.0.24_Debian-10sarge1-log for pc-linux-gnu on i386 (Source distribution)
[28 Feb 2012 10:08] Tim Lammens
The connection string used

[28 Feb 2012 10:13] Tim Lammens
Problem did not occur with driver 5.0.8
[28 Feb 2012 19:44] Mark Matthews
Mysql-4.0.x is not really supported by newer versions of the driver. That version of the server has been end-of-life for quite some time (years). Have you considered upgrading to MySQL-5.5?
[13 Mar 2012 15:55] Tim Lammens
The client needs to be able to talk to different versions of the server, since it is not always an option to upgrade the server version...

The problem was solved by using a custom classloader to load an older version of the driver which does support 4.x, but the driver should do this internally...
[13 Mar 2012 16:12] Tonci Grgin
Tim, thanks for sharing your solution with us.

Now, I do not get "The client needs to be able to talk to different versions of the server, since it is not always an option to upgrade the server version..."
Driver *is* supporting too many versions already. As a matter of fact, it is supporting so many versions that I'm thinking of making a new release which will further narrow it down. After all, you're years and 4 major versions behind current GA.