Bug #7316 Statement.getConnection() is incorrect when used with PooledConnection
Submitted: 15 Dec 2004 13:16 Modified: 15 Dec 2004 22:15
Reporter: Marc Petit-Huguenin Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.0.16 OS:Any (All)
Assigned to: Mark Matthews CPU Architecture:Any

[15 Dec 2004 13:16] Marc Petit-Huguenin
Description:
A Statement created from a Connection created from a PooledConnection returns a different connection than the connection used to create it.
More precisely it returns the PooledConnection, instead of the Connection created from the PooledConnection.

The problem in this case is that using statment.getConnection().close() closes the physical connection instead of sending the ConnectionEvent to the pool manager

How to repeat:
import java.sql.*;
import javax.sql.*;

public final class Test {
    public static final void main(String[] args)
        throws Exception {

        final boolean[] lock = new boolean[1];
        com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource dataSource
= new com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource();
        dataSource.setServerName("xxxxxx");
        dataSource.setDatabaseName("test");
        dataSource.setUser("root");
        dataSource.setPassword("xxxxx");
        PooledConnection pooledConnection = dataSource.getPooledConnection();
        pooledConnection.addConnectionEventListener(new
ConnectionEventListener() {
            public void connectionClosed(ConnectionEvent event) {
                synchronized (lock) {
                    lock[0] = true;
                    lock.notify();
                    }
                }
            public void connectionErrorOccurred(ConnectionEvent event) {
                }
            });
        Connection connection = pooledConnection.getConnection();
        Statement statement = connection.createStatement();
        synchronized (lock) {
            statement.getConnection().close();
            lock.wait(1000);
            assert lock[0] : "Event connectionClosed not received in 1000
millisconds";
            }
        }
    };
[15 Dec 2004 22:15] Mark Matthews
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html