| Author |
Insert and MoveFirst
|
Minh Phan
Greenhorn
Joined: Sep 23, 2004
Posts: 8
|
|
After I inserted a record to Access database and call first to move to the first record the following error message is displayed: java.sql.SQLException: ResultSet is closed. Here is the code. Please help. import java.io.*; import java.sql.*; class MyInsert { static private Statement st; static private Connection con; static private ResultSet rs; public static void main(String[] args) { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection( "jdbc dbc:library","",""); st = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = st.executeQuery("select bkCode,bkName,bkAuthor,bkAvailableQty from book"); } catch(Exception e){ System.out.println("Error opening connection: " + e); } try { String bc = "AAA"; String bn = "BBB"; String ba = "CCC"; int baq = 1; String query = "Insert into book Values('" + bc + "', '" + bn + "', '" + ba + "', " + baq + ")"; System.out.println(query); // this should looks like your commented line below int result = st.executeUpdate(query); if(result==1) System.out.println("1 record inserted"); else System.out.println("Sorry...Unkown error"); rs.first(); } catch(SQLException e){ System.out.println("Error inserting record: " + e); } } }
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
|
Since you are performing the query prior to executing the insert, why would you expect the result set obtained before the insert to reflect a record that you added after obtaining it?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Minh Phan
Greenhorn
Joined: Sep 23, 2004
Posts: 8
|
|
Thanks! But what is the way to design an interface by which the user can move through all records as well as update and delete some of the? I appreciate reply from you all!
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
|
Look at the Javadoc for ResultSet and you will find methods (assuming JDBC 2) that answer your questions.
|
 |
 |
|
|
subject: Insert and MoveFirst
|
|
|