Bug #32587 ConnectionWrapper#prepareStatement(String arg0, int arg1) always returns null
Submitted: 21 Nov 2007 17:56 Modified: 22 Nov 2007 15:07
Reporter: Andrei Ivanov Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:5.1.5 OS:Any
Assigned to:

[21 Nov 2007 17:56] Andrei Ivanov
Description:
I'm trying to insert an object in a mysql db, but an error apeared when obtaining the generated key for the object.
After investigating, I found the obvious error in the jdbc driver:

com.mysql.jdbc.jdbc2.optional.ConnectionWrapper contains this methods:

/**
 * @see Connection#prepareStatement(String, int)
 */
public java.sql.PreparedStatement prepareStatement(String arg0, int arg1)
		throws SQLException {
	checkClosed();

	try {
		PreparedStatementWrapper.getInstance(this, this.mpc, this.mc
				.prepareStatement(arg0, arg1));
	} catch (SQLException sqlException) {
		checkAndFireConnectionError(sqlException);
	}

	return null; // we don't reach this code, compiler can't tell
}

/**
 * @see Connection#prepareStatement(String, int[])
 */
public java.sql.PreparedStatement prepareStatement(String arg0, int[] arg1)
		throws SQLException {
	checkClosed();

	try {
		PreparedStatementWrapper.getInstance(this, this.mpc, this.mc
				.prepareStatement(arg0, arg1));
	} catch (SQLException sqlException) {
		checkAndFireConnectionError(sqlException);
	}

	return null; // we don't reach this code, compiler can't tell
}

/**
 * @see Connection#prepareStatement(String, String[])
 */
public java.sql.PreparedStatement prepareStatement(String arg0,
		String[] arg1) throws SQLException {
	checkClosed();

	try {
		PreparedStatementWrapper.getInstance(this, this.mpc, this.mc
				.prepareStatement(arg0, arg1));
	} catch (SQLException sqlException) {
		checkAndFireConnectionError(sqlException);
	}

	return null; // we don't reach this code, compiler can't tell
}

Notice that a return call is missing and they always return null.

Version 5.0.8 is fine.

How to repeat:
I don't think instructions are needed here, the bug is obvious.

Suggested fix:
Modify the methods to return the prepared statements.
[22 Nov 2007 15:07] Mark Matthews
This is a duplicate of BUG#32101, which has already been fixed in the source repository.