Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception while inserting a row with resultSet.insertRow()

 
Raj Verma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to insert a row in Access db using resultSet.moveToInsertRow() and then resultSet.insertRow. But it gives me the following error which occurs when it tries to execute resultSet.insertRow statement.
java.lang.ArrayIndexOutOfBoundsException
at sun.jdbc.odbc.JdbcOdbcResultSet.bindCol(JdbcOdbcResultSet.java:4485)
at sun.jdbc.odbc.JdbcOdbcResultSet.insertRow(JdbcOdbcResultSet.java:3941)
I am using updateXXX to update the columns.
I can connect to database and navigate through the resultset, but problem occurs only while inserting a row.
Can anyone please guide me to work around this problem.
Thanks
 
Smita Tyagi
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Raj,
Would you send me the code where you are trying this. I will try my best to help.
Smita
 
Raj Verma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Smita, here is the code. The data[][] stores one row and according to the type of the column, it executes updates.
ResultSetMetaData metaData; //Initialized in other proc
ResultSet resultSet; //Initialized in other proc

String[][] data; //holds a single row at a time along with col
// names. eg data[0][0] = colname &
// data[0][1] = value of colname
resultSet.moveToInsertRow();
for(int i = 0; i < data.length; i++)
{
colPos = resultSet.findColumn(data[i][0]);
switch (metaData.getColumnType(colPos))
{
case Types.INTEGER :
if (metaData.isAutoIncrement(colPos) == false)
{
resultSet.updateInt(data[i][0], Integer.parseInt(data[i][1]));
}
break;
case Types.VARCHAR :
resultSet.updateString(data[i][0], data[i][1]);
System.out.println("hey default");
break;
}
}
resultSet.insertRow(); // This is the place where the error
// occurs
Hope this code is clear. Please let me know if you have any questions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic