• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resultsets survives failure

 
satish pune
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having java code the snippets of which are

Connection con = DriverManager.getConnection("-------");
Statement stmt = con.createStatement("----");
ResultSet rs = stmt.executeQuerty("Select * from Emp");

After executing this statement if the oracle database server crashes,I still want to maintain my resultset.Would the object "rs" still pursive or not?
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, that resultset is dependent on the connection object being valid. If the server crashes, the connection object is hosed. The next time you try to use it, you will probably receive an SQLException that's wrapped around an IOException.

For that and other reasons, it is often a good idea to immediately read your ResultSet and store it into a disconnected data structure. For example, a simple way to do that is to iterate through the ResultSet and store each record into an Onject[] array and put each array into an ArrayList. Once you have your ArrayList built, you no longer need the ResultSet and you can close it.

Of course, if the db server crashes while you are still iterating the ResultSet, your out of luck.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic