• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

oracle resultset closing

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am trying to iterate a resulset returned by a procedure using Java 1.3.0/JDBC /classes12.zip
when i do Result.next, it says Connection closed.
what may be the reason ?
 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.
Please change your name to comply with the naming policy to which you agreed when you registered.
You can change your name here:
here

You can also find the naming policy here:
http://www.javaranch.com/name.jsp
Thank You!
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check whether u can have closed the connection before calling resultset.next(). It would be better if u paste the code here.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a problem I had not too long ago. From what I remember, it seems that if you create a Connection object in the method you are calling and then try to pass back a ResultSet object, the garbage collector will close the connection and therefore the ResultSet object before it gets back to the calling method.
We had two work-arounds for this. One was to never pass ResultSet objects, but rather vectors, arrays, custom objects, whatever containing the data back. The second solution was to create the Connection object in the calling method then pass the Connection to the called method, use the passed Connection to execute the query, pass back the ResultSet, then close the Connection after the ResultSet has been used.
This might give you the gist of passing the Connection object:
public callingMethod()
{
Connection myconn =
ConnectionPool.getConnection();
ResultSet rs;
rs = queryMethod(someString, myconn);
doSomthingWithRS(rs);
rs.close();
myconn.close();
}
public queryMethod(String someString,
Connection myconn)
{
ResultSet rs;
String sql = "select something from somewhere
where somestring = " + someString;
PreparedStatement ps =
myconn.prepareStatement(select);
ps.execute();
rs = ps.getResultSet();
return rs;
}
Hope this helps!
 
Are you here to take over the surface world? Because this tiny ad will stop you!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic