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.
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.