Java/Result set is closed
Hi Harper... Its nice to ask you doubts after long time..
public static void main(String args)
Connection con = DriverManager.getConnection("jdbc:odbc:mvp");
Statement st = con.createStatement();
Statement st1 = con.createStatement();
int i = 0;
ResultSet rs = st.executeQuery("select ipm from mvp ");
ResultSet rs1 = st1.executeQuery("select ipp from mvp ");
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.