• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resultset question

 
sugath nelabhotla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic