Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting a row using insertRow() method

 
Gurpreet Sachdeva
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just trying to insert a row using the insertRow() method of ResultSet class but it is giving me an ArrayIndexOutOfBoundsException. The code was as under:
<pre>
import java.sql.*;
class data1 {
public static void main(String args[]) throws Exception
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:mydsn1");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT * from emp2");
rs.moveToInsertRow();
rs.updateInt(1, 2);
rs.updateInt(2,35);
rs.updateInt(3, 3);
rs.insertRow();//This line gives me ArrayIndexOutOfBoundsException
rs.moveToCurrentRow();
}catch(Exception e){System.out.println("SQL Exception raised "+ e);}
}
}
</pre>
Please help me.
Regards
Gurpreet Sachdeva
 
Gurpreet Sachdeva
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Help me I need it urgently.
 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is jdbcOdbcbridge bug
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same problem was answered about 3 posts back (eventually) http://www.javaranch.com/ubb/Forum3/HTML/001683.html
you'll have to either find a driver that supports programmatic updates or stick with the more basic (and reliable) SQL DML statements.
Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic