Forums Register Login

Operation not allowed after ResultSet closed

+Pie Number of slices to send: Send
Hi,
I have done a java program with mysql.I got the output.but i am getting the following sql exception error
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.ResultSet.checkClosed(ResultSet.java:3601)
at com.mysql.jdbc.ResultSet.next(ResultSet.java:2478)
at Dis.main(Dis.java:22)
my code:
import java.sql.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
import java.sql.ResultSet;
public class Dis
{
public static void main (String[] args)
{

Statement st;
Connection con = null;

try



{



Class.forName("com.mysql.jdbc.Driver").newInstance();

con = DriverManager.getConnection("jdbc:mysql://192.168.1.5:3306/dialer","dialer","1234");

st = con.createStatement();
ResultSet rs1=st.executeQuery("select ratio from aircel where id='3'");
while(rs1.next())
{
int b=rs1.getInt("ratio");
System.out.println(b);
for(int i=0;i<=b;i++)
{

ResultSet rs = st.executeQuery("select phone from aircel where disposition='1' and id='"+ i +"'");



while(rs.next())



{



int a = rs.getInt("phone");

System.out.println(a);



}



} }



}
catch (Exception e)
{
e.printStackTrace();

}
finally
{
if (con != null)
{
try
{
con.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
please do help me.
+Pie Number of slices to send: Send
Please use code tags when you post code, so that the forum can display your code properly.

You are re-using the same Statement object ('st') for both queries. Don't do that; instead, create a new Statement object for each query.
+Pie Number of slices to send: Send
Thanks for your reply.my program is running well.
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 19025 times.
Similar Threads
nested ResultSets
Statement Closed Error - please help
Help requested
SQL Exception
Refresh a Servlet page
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:58:58.