• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can i use the resultset simultaneously?

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iam using the same resultset simultaneously but iam closing it before using it next time..will it create any problem

Iam getting ResultSet is closed exception...
please tell me where exactly iam doing wrong...here is the code..

public String update(String studentID,String email,String address,String contactNumber)
{
try
{
rs=st.executeQuery("select count(*) from memdetails where memid='"+studentID+"'");
while(rs.next())
{
counter=rs.getInt(1);
}
if(counter>0)
{
st.executeUpdate("update memdetails set emailid='"+email+"',address='"+address+"',phno='"+contactNumber+"' where memid='"+studentID+"'");
rs.close();
rs=st.executeQuery("select count(*) from SC_UpdateSmartcard where memid='"+studentID+"' and file_id='3003'");
while(rs.next())
{
counter=rs.getInt(1);
}
if (counter>0)
{
st.executeUpdate("update SC_UpdateSmartcard set status='y' where memid='"+studentID+"' and file_id='3003'");
}
else
{
st.executeUpdate("insert into SC_UpdateSmartcard(student_rollno,file_id ,status) values ('"+studentID+"','3003','y')");
}
return "Data Updated Successfully";
}
else
{
return "Please Enter User Personal Data 1";
}
}
catch(Exception e)
{
System.out.println("3003:"+e.getMessage());
return "Exception Encountered";
}
finally
{
try
{
rs.close();
}
catch(Exception e)
{
System.out.println("3003:"+e.getMessage());
}
}
}

The exception is being caugth in the catch and finally block.........
can any one please tell me where exactly iam doing wrong
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you closed result set , then you can not use it anymore. Reusing the same result set possible, however:
1. it will manage the same result data
2. it can be memory costly operation for some JDBC drivers, for example Oracle driver suck entire result memory allowing you to scroll over it bi directionally.
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont want resuming the same resultset.. when i create another resultset...as in the code will it create any problems or else shall i make it to null i.e rs=null; before creating another resultset with the same reference... Also can you tell me how to know whether a result set is closed or not..

Now i changed little bit i didnot closed resultset anywhere except in the finally block..but it is throwing ResultSet is closed exception
in the finally block

public String update(String studentID,String email,String address,String contactNumber)
{
try
{
rs=st.executeQuery("select count(*) from memdetails where memid='"+studentID+"'");
if(rs.next())
{
counter=rs.getInt(1);
}
if(counter>0)
{
st.executeUpdate("update memdetails set emailid='"+email+"',address='"+address+"',phno='"+contactNumber+"' where memid='"+studentID+"'");
System.out.println("rsd"+rs);
rs=null;
/*updating the editing information into the table*/
rs=st.executeQuery("select count(*) from SC_UpdateSmartcard where student_rollno='"+studentID+"' and file_id='3003'");
while(rs.next())
{
counter=rs.getInt(1);
}
if (counter>0)
{
st.executeUpdate("update SC_UpdateSmartcard set status='y' where student_rollno='"+studentID+"' and file_id='3003'");
}
else
{
st.executeUpdate("insert into SC_UpdateSmartcard(student_rollno,file_id ,status) values ('"+studentID+"','3003','y')");
}
return "Data Updated Successfully";
}
else
{
return "Please Enter User Personal Data 1";
}
}
catch(Exception e)
{
System.out.println("3003:"+e.getMessage());
return "Exception Encountered";
}
finally
{
try
{
rs.close();
}
catch(Exception e)
{
System.out.println("3003:"+e.getMessage());
}
}
}

i modified little bit..it is giving ResultSet is closed in the finally block.. can you give me the reason for that
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Old result set will be collected by GC, as only you assign your resultset variable a new value. No nulling required.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Abhishek Reddy Chepyala,

Can you please post your code using [CODE] tags so that it will look clear?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Drivers generally permit only a single ResultSet per Statement. So if you submit a Statement.executeUpdate, any ResultSet obtained previously through that Statement is invalidated.

Instead of doing an "rs.close" at the end, do a "st.close". It will close the ResultSet as well, if necessary.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thats correct. Once the resultset is closed, you may not get its content back. Perhaps, it might be a costly operation as D Rog said.

Please have a look at this thread for using [CODE] tags!
[ July 20, 2007: Message edited by: Raghavan Muthu ]
 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply.......i have replaced rs.close() with st.close() updated successfully but while reading it is giving Invalid Handle Exception..
when replace back st.close() with rs.close() it is working why iam unable to understand
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic