• 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

Resultset question

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic