Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Operation not allowed after ResultSet closed

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.my program is running well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic