This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

oracle resultset closing

 
ajap
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 ?
 
Michael Pearson
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • 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!
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Chuck Lowry
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic