Bug #3911 Binding parameters in PreparedStatenent fails
Submitted: 27 May 2004 10:59 Modified: 27 May 2004 17:02
Reporter: Johan Andersson Email Updates:
Status: Can't repeat Impact on me:
Category:Connector / J Severity:S1 (Critical)
Version:Connector/J 3.1.1 alpha OS:Linux (RH 9)
Assigned to: Mark Matthews CPU Architecture:Any

[27 May 2004 10:59] Johan Andersson

I run this:
	// Preparing statement
		// INSERT INTO XYZ SET X=?, Y=?, Z=?, W=?, U=?, timestamp=NOW()
Binding parameters does not work that well:

		insertPreparedStatement.setString(1, a);
		insertPreparedStatement.setString(2, b);
		insertPreparedStatement.setString(3, c);
		insertPreparedStatement.setString(4, d);
		insertPreparedStatement.setString(5, e);
		// Execute SQL query

results in:

java.sql.SQLException: java.lang.ArrayIndexOutOfBoundsException: 2
        at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1150)
        at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:804)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1789)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1597)
        at CUSTOMER.store(TestMain.java:323)
        at TestMain.main(TestMain.java:35)

How to repeat:
Contact bug reporter for test program to reproduce the problem if you need to.
[27 May 2004 17:02] Mark Matthews
I can't repeat this with the current source tree of Connector/J 3.1, you might want to test with a nightly snapshot of 3.1 from http://downloads.mysql.com/snapshots.php

(this looks suspiciously like a bug that I know has been fixed).
[6 Jun 2004 22:22] Koen Heene
I had the same problem using ConnectorJ 3.1.1 with MySQL 4.1.2 Linux. (The problem did NOT happen when using ConnectorJ 3.1.1 with MySQL 4.1.1 Windows.) It was solved by downloading the nightly build of ConnectorJ on 2004/06/05. Then I had another problem :-( similar to the problem described in bug report 3921. That one I solved using the tip from Mark Matthews (useServerPrepStmts=false).

It is a bit of a struggle to find out which version of ConnectorJ is -exactly- compatible with which version of MySQL daemon. Maybe a table in the docs would be nice.

Koen Heene
[25 Jun 2004 16:37] Niklas Lindholm
I have run into something very similar using MySQL 4.1.2 and Connector/J 3.1.2. It occured on some very simple select statements like this:

            ps = con.prepareStatement
                ("SELECT CategoryId, Name FROM Categories " +
                 "WHERE SiteId = " + siteId);
            ps.setInt(1, siteId);
            rs = ps.executeQuery();

I can't seem to find any pattern in when it fails and when it doesn't fail. The same method works in some situations but not in others.

I tried using tonight's nightly build (mysql-connector-java-3.1-nightly-20040625-bin.jar) and that helped for statements that failed before. But instead a new statement started to fail.