Re: Problem with PreparedStatements parameter settings
Posted by: Mark Matthews
Date: February 01, 2005 08:24AM

tolle wrote:
> Hi,
>
> I am using MySQL version 4.1.8 and MySQL
> Connector/J version 3.1.6.
>
> When running the following code I receive the
> error detailMessage=
> "java.lang.ArrayIndexOutOfBoundsException"
> when executing the prepared statement. (Using the
> statement st
> the insertion works fine.)
>
> public void insert() {
> try {
> Statement st = this.con.createStatement();
> st.execute("insert into resources (ID, URI, LIT)
> values (1, 'test', 0)");
> con.commit();
> pstmt = this.con.prepareStatement("insert into
> resources (ID, URI, LIT) values (?, ?, ?)");
> pstmt.setInt(1,1);
> pstmt.setString(2,"test");
> pstmt.setInt(3,0);
> pstmt.execute();
> } catch (Exception e) {
> System.out.println(e);
> }
> }
>
> This was a test run to better locate the error.
> The original problem occured by porting an
> application running on IBMs DB2 to MySQL.
> There I have a bunch of PreparedStatements and the
> error message I receive
> there differs from the one above.
> At the first time of using a PreparedStatement
> there I receive:
> detailMessage= "Parameter index out of bounds. 2
> is not between valid values of 1 and 1"
> ... but there are 2 ? in the SQL statement:
> originalSql= "insert into resources (ID, URI, LIT)
> values (?, ?, 0)"
>
> ... later in the execution I receive:
> detailMessage= "Statement parameter 4 not set."
> ... having the SQL statement:
> originalSql= "insert into classes values (?, ?,
> ?)"
>
>
> Am I doing something wrong?
> Thanks for any help.
> Karsten


Karsten,

That sounds a lot like you're using an older version of Connector/J 3.1, which did have an issue with this. Make doubly sure you don't have some older version laying around in your classpath.

A _full_ stack trace from your exception might help too, as it's often quite obvious to detect when you're not using the latest version (i.e. the line #'s/call stack doesn't line up).

There are thousands of prepared statements just like yours in our testsuite, and there are thousands of people using 3.1.6 with prepared statements and MySQL-4.1, so there is a strong likelyhood that either the issue you're seeing is _very_ directly related to your schema, or (more likely), you're not really running Connector/J 3.1.6.

-Mark

Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools
Oracle
http://www.mysql.com/products/enterprise/monitor.html

Options: ReplyQuote


Subject
Written By
Posted
Re: Problem with PreparedStatements parameter settings
February 01, 2005 08:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.