Subject Re: Exception preparing statement
Author Roman Rokytskyy
Hi,

> I have this exception being thrown ...
>
> java.lang.ArrayIndexOutOfBoundsException: 2
> at ....

Can you prepare reproducable test case? I tried your code with latest
CVS version of JayBird (but we did not fix anything there since
release) and it works fine....

Thanks!
Roman Rokytskyy

P.S. Here's the code of my test case, I did not put it into the CVS,
because no problem were found so far. Note, I had to replace INT64
with NUMERIC(18,0), for some reasons FB 1.5 RC1 does not know this alias.

/*
* Created on 16.05.2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.firebirdsql.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

/**
*
* @author <a href=mailto:rrokytskyy@...>Roman
Rokytskyy</a>
*/
public class TestReportAOBEX extends BaseFBTest {

public TestReportAOBEX(String name) {
super(name);
}

public static final String CREATE_TABLE = ""
+ "CREATE TABLE MESSAGES"
+ "("
+ "ID NUMERIC(18,0) NOT NULL,"
+ "FOLDER_ID NUMERIC(18,0),"
+ "REFERENCE_ID NUMERIC(18,0),"
+ "EXTERNAL_REF VARCHAR(80) CHARACTER SET UNICODE_FSS,"
+ "MSG_TYPE SMALLINT,"
+ "MSG_CLS VARCHAR(40) CHARACTER SET UNICODE_FSS,"
+ "MSG_FROM BLOB SUB_TYPE TEXT SEGMENT SIZE 80 CHARACTER SET
ASCII,"
+ "MSG_TO BLOB SUB_TYPE TEXT SEGMENT SIZE 80 CHARACTER SET ASCII,"
+ "MSG_CC BLOB SUB_TYPE TEXT SEGMENT SIZE 80 CHARACTER SET ASCII,"
+ "MSG_SUBJECT VARCHAR(200) CHARACTER SET UNICODE_FSS,"
+ "MSG_SIZE INTEGER,"
+ "HEADER_DATA BLOB SUB_TYPE TEXT SEGMENT SIZE 1024 CHARACTER
SET ASCII,"
+ "COMMENTS BLOB SUB_TYPE TEXT SEGMENT SIZE 200 CHARACTER SET
ASCII,"
+ "ACCOUNT_ID VARCHAR(22) CHARACTER SET UNICODE_FSS,"
+ "COMPOSE_DURATION INTEGER,"
+ "PRIORITY SMALLINT,"
+ "URGENCY NUMERIC(18,0),"
+ "CREATE_TIME TIMESTAMP,"
+ "READ_TIME TIMESTAMP,"
+ "REPLY_TIME TIMESTAMP,"
+ "FORWARD_TIME TIMESTAMP,"
+ "FLAG_FLAG SMALLINT NOT NULL,"
+ "APPROVE_FLAG SMALLINT NOT NULL,"
+ "WATCH_FLAG SMALLINT NOT NULL,"
+ "COMPLETE_FLAG SMALLINT NOT NULL,"
+ "TEXT_CONTENT BLOB SUB_TYPE TEXT SEGMENT SIZE 1024 CHARACTER
SET ASCII,"
+ "HTML_CONTENT BLOB SUB_TYPE TEXT SEGMENT SIZE 1024 CHARACTER
SET ASCII,"
+ "KEYWORDS BLOB SUB_TYPE TEXT SEGMENT SIZE 1024 CHARACTER SET
ASCII,"
+ "TOPICS BLOB SUB_TYPE TEXT SEGMENT SIZE 1024 CHARACTER SET
ASCII,"
+ "MIME_CONTENT BLOB SUB_TYPE TEXT SEGMENT SIZE 4096 CHARACTER
SET ASCII,"
+ "SEND_TIME TIMESTAMP,"
+ "REASON BLOB SUB_TYPE TEXT SEGMENT SIZE 80 CHARACTER SET
UNICODE_FSS,"
+ "MOVE_TIME TIMESTAMP,"
+ "FLAG_TIME TIMESTAMP,"
+ "ORIGINAL_FOLDER_ID NUMERIC(18,0),"
+ "TRANSFER_TIME TIMESTAMP,"
+ "INCIDENT_ID NUMERIC(18,0),"
+ "PRIMARY KEY (ID)"
+ ")"
;

public static final String DROP_TABLE = ""
+ "DROP TABLE MESSAGES"
;

private Connection connection;

protected void setUp() throws Exception {
super.setUp();

Class.forName(FBDriver.class.getName());
connection = DriverManager.getConnection(DB_DRIVER_URL, DB_INFO);

Statement stmt = connection.createStatement();

try {
stmt.executeUpdate(DROP_TABLE);
} catch(SQLException ex) {
// ignore, most likely it does not exist.
}

try {
stmt.executeUpdate(CREATE_TABLE);
} finally {
stmt.close();
}
}

protected void tearDown() throws Exception {
Statement stmt = connection.createStatement();

stmt.executeUpdate(DROP_TABLE);

connection.close();
}


private static String _retrieveRecordFields =

"FOLDER_ID,REFERENCE_ID,EXTERNAL_REF,MSG_TYPE,MSG_CLS,MSG_FROM,MSG_TO,MSG_CC,"
+
"MSG_SUBJECT,MSG_SIZE,COMMENTS,ACCOUNT_ID,COMPOSE_DURATION," +
"SEND_TIME,PRIORITY,CREATE_TIME," +

"READ_TIME,REPLY_TIME,APPROVE_FLAG,FLAG_TIME,WATCH_FLAG,TOPICS,URGENCY,MOVE_TIME,REASON,INCIDENT_ID
";

public void testPrepareStatement() throws Exception {
final String sql = "SELECT " + _retrieveRecordFields +
" FROM MESSAGES WHERE ID=?;";
PreparedStatement ps = null;
try {
connection.setAutoCommit(false);
ps = connection.prepareStatement(sql); ///////LINE 2385 IS
HERE
} catch(ArrayIndexOutOfBoundsException ex) {
assertTrue("should not fail", false);
} finally {
if (ps != null)
ps.close();
connection.setAutoCommit(true);
}
}

}