You are here:

Java/Result set is closed


Hi Harper... Its nice to ask you doubts after long time..

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

class fin1
 public static void main(String args[])
     Connection con = DriverManager.getConnection("jdbc:odbc:mvp");

     Statement st = con.createStatement();
     Statement st1 = con.createStatement();
     int i = 0;
  String op,str1,so,ss,pp,ph;
  StringBuffer stt,pf;
     ResultSet rs = st.executeQuery("select ipm from mvp ");
     ResultSet rs1 = st1.executeQuery("select ipp from mvp ");
     while (
   str1 = rs.getString(1);
       int k = str1.indexOf(';');
      op = str1.substring(0, k);
       String qq="UPDATE mvp SET opm = '" + op + "' , opp = '" + op +"' WHERE ipm = '" + str1 + "'";
   catch (Exception localException)

when ever i execute this query it shows resultset is closed error.

how to fix it.


I think the issue is that you are trying to reuse the same Connection object for multiple queries. What you should do is use the update functionality of ResultSet, which will let you update the value of the current row as you are updating it. To do this you need to modify your query to include the 'opm' field like:
ResultSet rs = st.executeQuery("select ipm,opm from mvp ");

Then in your while loop:

This should allow you to update the value without having to execute another query.


All Answers

Answers by Expert:

Ask Experts


Artemus Harper


I have a Masters in computer science. I can answer questions on core J2SE, swing and graphics. Please no questions about JSP or J2ME.


I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. Some experience in bio-informatics. Basics in c++ and c#

Washington State University

MS in Computer Science from Washington State University and a BS in Mathematics and Computer Science from Central Washington University.

©2017 All rights reserved.