This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes java.lang.ArrayIndexOutOfBoundsException: 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "java.lang.ArrayIndexOutOfBoundsException: 1" Watch "java.lang.ArrayIndexOutOfBoundsException: 1" New topic

java.lang.ArrayIndexOutOfBoundsException: 1

Reshma Rangarajan

Joined: Nov 02, 2010
Posts: 8

I am trying to do an insert into table using PreparedStatement. I get a java.lang.ArrayIndexOutOfBoundsException: 1 exception at pStatement.setString(2, id);. Here's the code and stack trace. Can someone please let me know whats the bug in this code. Thanks in advance


java.lang.ArrayIndexOutOfBoundsException: 1
at oracle.jdbc.dbaccess.DBDataSetImpl._getDBItem(

at oracle.jdbc.dbaccess.DBDataSetImpl._createOrGetDBItem(DBDataSetImpl.j
at oracle.jdbc.dbaccess.DBDataSetImpl.setBytesBindItem(DBDataSetImpl.jav
at oracle.jdbc.driver.OraclePreparedStatement.setItem(OraclePreparedStat
at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedSt
at com.comp.sample.datalayer.SampleInsert.testInsert(Unknown Sourc
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
can you please tell me what is billNumbers which you have used in for loop.
whether you checked in the line number 378.
put some logger or sop to check the value of id inside the else part.


For java examples,ebooks,interview questions,visit this blog
Kuldip Shetty
Ranch Hand

Joined: Jan 07, 2010
Posts: 42

Both the select and Insert query statements are using the same preparedStatement variable pStatement. While creating the preparedStatement instance for insert query guess you forgot to intialise to a new preparedStatement variable (LHS is missing)

Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
A general suggestion. It would be better if you Prepare your SELECT and INSERT statements outside the loop. If you are preparing the statements inside the loop, then you are soft parsing the query for each iteration of the loop and there by loosing the primary advantage of prepared statement - prepare once, execute many times.

Jan Cumps

Joined: Dec 20, 2006
Posts: 2541

Summarizing the great advise from the replies you received:

OCUP UML fundamental and ITIL foundation
Reshma Rangarajan

Joined: Nov 02, 2010
Posts: 8
that was spot on. Initializing the second prepareStatement solved my issue.

iStatement = conn.prepareStatement(insertString);

I have used two different prepared statements now for query and insert.

PS: billNumbers was an array of 'Long' values.

Thanks a lot to all of you for the help.
wood burning stoves
subject: java.lang.ArrayIndexOutOfBoundsException: 1
It's not a secret anymore!