File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes  Operation not allowed after ResultSet closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " Operation not allowed after ResultSet closed" Watch " Operation not allowed after ResultSet closed" New topic
Author

Operation not allowed after ResultSet closed

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thanks for your reply.my program is running well.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Operation not allowed after ResultSet closed
 
Similar Threads
Refresh a Servlet page
Statement Closed Error - please help
SQL Exception
Help requested
nested ResultSets