aspose file tools*
The moose likes JDBC and the fly likes Exception while inserting a row with resultSet.insertRow() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception while inserting a row with resultSet.insertRow()" Watch "Exception while inserting a row with resultSet.insertRow()" New topic
Author

Exception while inserting a row with resultSet.insertRow()

Raj Verma
Greenhorn

Joined: Apr 17, 2001
Posts: 5
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


/.\ /.\<BR> ----<BR> `..'
Smita Tyagi
Greenhorn

Joined: May 09, 2001
Posts: 21
Hello Raj,
Would you send me the code where you are trying this. I will try my best to help.
Smita
Raj Verma
Greenhorn

Joined: Apr 17, 2001
Posts: 5
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception while inserting a row with resultSet.insertRow()