The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

insert programtically

Posted by vishal on May 09, 2001 at 8:31 AM

Topic: A call to ResultSet.insertRow() causes ArrayIndexOutOfBoundsException

Hi,

I would be grateful if somebody could help me with the following problem:

I tried to run a part of the example code that I downloaded from Sun's web site for the book "JDBC API Tutorial and reference etc"
- after I made all the necessary changes - and I got:

"Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException
at sun.jdbc.odbc.JdbcOdbcResultSet.bindCol(Unknown Source) at sun.jdbc.odbc.JdbcOdbcResultSet.insertRow(Unknown Source) at InsertRow.main(InsertRow.java:40)"

Am I doing something wrong or the code of the example is wrong?
I use JDK1.3, the jdbc:odbc brigde and SQLserver 7.0

my dsn name:vishal

import java.sql.*;
//import javax.sql.*;

public class insert
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:vishal");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("SELECT * FROM COFFEES");
rs.moveToInsertRow();
rs.updateString("COF_NAME", "Kona"); rs.updateInt("SUP_ID", 150);
rs.updateFloat("PRICE", 10.99f);
rs.updateInt("SALES", 0);
rs.updateInt("TOTAL", 0);
rs.insertRow();
rs.beforeFirst();
System.out.println("After Insertion");
while(rs.next())
{
String name=rs.getString("COF_NAME");
String add=rs.getString("PRICE");
System.out.println(name + " "+add);
}
rs.close();
stmt.close();
con.close();
}
catch(java.lang.ClassNotFoundException e1)
{
System.out.println("Exception is e1 "+e1.getMessage());
}
catch(SQLException e)
{
System.out.println("Exception is e "+e.getMessage());
}
}
}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us