FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Using 2 digit parameter numbers in queries defined using annotations fails.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
@Update (sql="INSERT INTO app.person (first_name, last_name, middle_name, nickname, " +
"title, suffix, sex, birth_date, work_phone1, work_phone2) " +
"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, " +
" ?9, ?10)")
public int addPerson(
String p_firstName, String p_lastName, String p_middleName,
String p_nickname, String p_title, String p_suffix, String p_sex,
Date p_birthDate, String p_workPhone1, String p_workPhone2);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful execution
ACTUAL -
End result is a parse error from the RDBMS (Derby). Through testing I've determined that the JDBC parser that determines parameter numbers only looks at the first character after the ?. It tries to parse this as the number. When you use an invalid character after the ? (say, a letter), you get a NumberFormatException (expected). However, if you put 2 letters, you only get the exception mentioning the first of the two characters. Obviously, it is not checking for multiple digit numbers for the parameters. This is why an incorrect SQL statement is being passed to the DBMS engine.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
ERROR 42X01: Syntax error: Encountered "0" at line 1, column 242.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver30.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at com.sun.sql.QueryObjectGeneratorImpl.getUpdateImpl(QueryObjectGeneratorImpl.java:469)
at com.sun.sql.QueryObjectGeneratorImpl.access$200(QueryObjectGeneratorImpl.java:24)
at com.sun.sql.QueryObjectGeneratorImpl$3.run(QueryObjectGeneratorImpl.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.sql.QueryObjectGeneratorImpl.invoke(QueryObjectGeneratorImpl.java:226)
REPRODUCIBILITY :
This bug can be reproduced always.
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Using 2 digit parameter numbers in queries defined using annotations fails.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
@Update (sql="INSERT INTO app.person (first_name, last_name, middle_name, nickname, " +
"title, suffix, sex, birth_date, work_phone1, work_phone2) " +
"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, " +
" ?9, ?10)")
public int addPerson(
String p_firstName, String p_lastName, String p_middleName,
String p_nickname, String p_title, String p_suffix, String p_sex,
Date p_birthDate, String p_workPhone1, String p_workPhone2);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful execution
ACTUAL -
End result is a parse error from the RDBMS (Derby). Through testing I've determined that the JDBC parser that determines parameter numbers only looks at the first character after the ?. It tries to parse this as the number. When you use an invalid character after the ? (say, a letter), you get a NumberFormatException (expected). However, if you put 2 letters, you only get the exception mentioning the first of the two characters. Obviously, it is not checking for multiple digit numbers for the parameters. This is why an incorrect SQL statement is being passed to the DBMS engine.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
ERROR 42X01: Syntax error: Encountered "0" at line 1, column 242.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver30.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at com.sun.sql.QueryObjectGeneratorImpl.getUpdateImpl(QueryObjectGeneratorImpl.java:469)
at com.sun.sql.QueryObjectGeneratorImpl.access$200(QueryObjectGeneratorImpl.java:24)
at com.sun.sql.QueryObjectGeneratorImpl$3.run(QueryObjectGeneratorImpl.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.sql.QueryObjectGeneratorImpl.invoke(QueryObjectGeneratorImpl.java:226)
REPRODUCIBILITY :
This bug can be reproduced always.