• 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

Newbie question... :(

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Sry for maybe stupid question..
I have a sql ResultSet like this:
ResultSet myResultSet = stmt.executeQuery(query);
but I want to dynamically change the var name of ResultSet like:
String res = myGeneratedResultSetname;
ResultSet res = stmt.executeQuery(query);
and thats shows error, cant convert string to resultset etc...
So is it possible to change ResultSet's var name, or I have to write exactly ResultSet varname = stmt.executeQuery(query);
I stuck on this problem, and already wasted about 3 hours trying to solve it..plz heeelp
Best regards...

[This message has been edited by Ilja Smoli (edited December 21, 2001).]
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're confusing the NAME of the ResultSet with the ResultSet OBJECT itself. You can change its name simply by creating a new ResultSet variable with the new name and assigning the old one:

But I'm not sure what you hope to gain. Both result set variables are pointing at the same object, and it's the object itself that has utility, not what you name the object.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


String res = myGeneratedResultSetname;
ResultSet res = stmt.executeQuery(query);


As far as my knowledge goes this is not possible. Name of a variable should known by the compiler, i.e during compile time.
What you are doing is generating a name during runtime and trying to create a variable in that name.
However to accomplish what you are trying to do, you can use a collection of ResultSets, like a vector of Resultsets, etc.
Ranchers,
Correct me if I'm wrong
Rex
 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, seems there is no way to do it, but I'll try to explain for what I tryed to do it.
Im trying to generate block of code (sql queries), using do..while loop, and as u know there can't be statements or Resultsets with same names, so it needs to be generated...
Ok maybe u could advise about generating code blocks using different way...and btw, about vectors, where can i get normal manual about it.
Thx a lot...
Best Regards, Ilja
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure I completely understand what you're trying to do, but maybe I can help with something...
Try something like this... with several resultSets:
ResultSet rs1;
ResultSet rs2;
ResultSet rs3;
ResultSet rs4;
rs1 = stmt.executeQuery( query1 );
while( rs1.next() ) {
rs2 = stmt.executeQuery( query2 );
while( rs2.next() ) {
rs3 = stmt.executeQuery( query3 );
while( rs3.next() ) {
rs4 = stmt.executeQuery( query4 );
while( rs4.next() ) {
out.println( rs1.getString( 1 ) + rs2.getString( 1 ) + rs3.getString( 1 ) + rs4.getString( 1 ) + "<br>" );
}
rs4.close();
}
rs3.close();
}
rs2.close();
}
rs.close();
Of course, once you're done with a resultSet you can use it again- just reassign it ( rs = stmt.executeQuery( query ); ). Hope this gives you some ideas-
-Pencil Ed
[This message has been edited by George Larry (edited December 28, 2001).]
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic