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:

Exception in database

Posted by Nirmala Selvaraju on May 12, 2001 at 2:51 AM


I tried to insert and update columns to both result set as well as database. In this connection, I used moveToInsertRow() method to move to cursor position to the row where the insertion should take place. While doing so, I am getting ArrayIndexOutOfBounds Exception. I am not able to insert to my resultset as well as database, though my stmt is TypeScrollSenstive and Updatable.]

I do not have problem in updating to my resultset as well as database. But whenever I use moveToInserRow() I am getting the same exception ArrayIndexOutOfBounds. New row is not getting inserted at all. What could be the problem. Kindly advise as early as possible.

My code segment is as follows.

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class eg extends JFrame implements ActionListener
{
Connection con;
ResultSet rs,rs1;
Statement st,st1;
JButton add;
JTextField t1,t2;
Container c;
eg()

{
c=getContentPane();
c.setLayout(null);
setBounds(300,300,300,300);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:oracle","guest","guest");
st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=st.executeQuery("select * from java_bom");
}catch(Exception e){System.out.print(e);}


add=new JButton("Add");
add.setSize(20,20);
add.setLocation(100,100);
c.add(add);

t1=new JTextField();
t1.setSize(20,20);
t1.setLocation(150,100);
c.add(t1);

t2=new JTextField();
t2.setSize(20,20);
t2.setLocation(200,100);
c.add(t2);
add.addActionListener(this);

}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==add)
{
try{
if(rs.next())
{
rs.moveToInsertRow();
rs.updateString("es_parent",t1.getText());
rs.updateString("es_child",t1.getText());
rs.updateFloat("en_pos",10000);
rs.updateString("en_slno",t1.getText());
rs.updateFloat("en_count",20000);
rs.updateString("es_exploded",t1.getText());
rs.insertRow();
rs.beforeFirst();
System.out.println("Row No "+rs.getRow());

}
}catch(SQLException se)
{System.out.print("SQL Error "+se);}
catch(Exception se)
{System.out.print("Error "+se);}
}
}
public static void main(String args[])
{
eg e=new eg();
e.show();
}
}





Replies:
  • re selvaraj May 24, 2001 at 7:20 AM (0)

Sponsored Links



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