The Artima Developer Community
Sponsored Link

Java Answers Forum
JDBC Help !!!

1 reply on 1 page. Most recent reply: May 19, 2003 10:18 AM by NSriram

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
NSriram

Posts: 4
Nickname: nan
Registered: May, 2003

JDBC Help !!! Posted: May 19, 2003 8:19 AM
Reply to this message Reply
Advertisement
Hello,
I downloaded the J2SE 1.4.1_02 from the Sun's site. The following piece of code in JDBC gives me an ArrayIndexOutOfBoundsException, especially the line, uprs.beforeFirst(). If I try running it without that line, it gives no error, I am getting the original rows, I mean the already existing rows. The new rows aren't inserted.

Also the same code works in Sun ONE Studio 4CE that I downloaded. And again, inserting the rows without the ResultSet cursor concepts gives no problems. What could be the reason?



try {
con = DriverManager.getConnection(url, "myLogin", "myPassword");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE );
ResultSet uprs = stmt.executeQuery("SELECT COF_NAME, SUP_ID, PRICE, SALES, TOTAL FROM COFFEES");

uprs.moveToInsertRow();
uprs.updateString("COF_NAME", "Kona");
uprs.updateInt("SUP_ID", 150);
uprs.updateFloat("PRICE", 10.99f);
uprs.updateInt("SALES", 0);
uprs.updateInt("TOTAL", 0);
uprs.insertRow();
uprs.updateString("COF_NAME", "Kona_Decaf");
uprs.updateInt("SUP_ID", 150);
uprs.updateFloat("PRICE", 11.75f);
uprs.updateInt("SALES", 0);
uprs.updateInt("TOTAL", 0);
uprs.insertRow();

uprs.beforeFirst();
while (uprs.next()) {
String name = uprs.getString("COF_NAME");
int id = uprs.getInt("SUP_ID");
float price = uprs.getFloat("PRICE");
int sales = uprs.getInt("SALES");
int total = uprs.getInt("TOTAL");
System.out.print(name + " " + id + " " + price);
System.out.println(" " + sales + " " + total);
}


uprs.close();
stmt.close();
con.close();

} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}


NSriram

Posts: 4
Nickname: nan
Registered: May, 2003

Re: JDBC Help !!! Posted: May 19, 2003 10:18 AM
Reply to this message Reply
I'm sorry. It's the line uprs.insertRow()that is giving me problems.
Thanks
NS

Flat View: This topic has 1 reply on 1 page
Topic: Broken Java News Link Previous Topic   Next Topic Topic: Refresh swing component using graphics

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use