File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Resultset question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Resultset question" Watch "Resultset question" New topic
Author

Resultset question

sugath nelabhotla
Greenhorn

Joined: Apr 24, 2006
Posts: 4
Hi, Can someone help me to find the answer the following questions:

1. Statement st = connec.createStatement();
Resultset rs1 = st.executeQuery("sql");
Resultset rs2 = st.executeQuery("sql");

Is this fine to use the same statement object to get one more resultset or will there be any problem ?

2. Can we pass the resultset obj from server to the client side ?
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Originally posted by sugath nelabhotla:
Hi, Can someone help me to find the answer the following questions:

1. Statement st = connec.createStatement();
Resultset rs1 = st.executeQuery("sql");
Resultset rs2 = st.executeQuery("sql");


As soon as the 2nd query is executed, rs1 is closed. This is required, and is explicitly noted in the Javadocs for ResultSet.




Is this fine to use the same statement object to get one more resultset or will there be any problem ?


You can certainly reuse a statement, but you have to understand the life-cycle of ResultSets, there are very significant limits on what you can do; you probably can't reuse them in the way you seem to be wanting to...



2. Can we pass the resultset obj from server to the client side ?


No. A ResultSet does not contain the results, it's a wrapper around a Connection that returns rows when next() is called. Passing a ResultSet in that way is somewhat like passing an Iterator to the client; the Iterator would need a lot of special code underneath it to work in that way, a standard Iterator won't work, and neither will a ResultSet. ResultSets are not serializable and cannot be made to be so.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Resultset question