Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Operation not allowed after ResultSet closed

 
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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.
 
I will suppress my every urge. But not this shameless plug:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic