File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Newbie question... :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Newbie question... :(" Watch "Newbie question... :(" New topic

Newbie question... :(

Ilja Smoli
Ranch Hand

Joined: Dec 02, 2001
Posts: 64
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).]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

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.

An IDE is no substitute for an Intelligent Developer.
Rex Rock
Ranch Hand

Joined: Jun 25, 2001
Posts: 82

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.
Correct me if I'm wrong
Ilja Smoli
Ranch Hand

Joined: Dec 02, 2001
Posts: 64
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
George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
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( ) {
rs2 = stmt.executeQuery( query2 );
while( ) {
rs3 = stmt.executeQuery( query3 );
while( ) {
rs4 = stmt.executeQuery( query4 );
while( ) {
out.println( rs1.getString( 1 ) + rs2.getString( 1 ) + rs3.getString( 1 ) + rs4.getString( 1 ) + "<br>" );
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).]
I agree. Here's the link:
subject: Newbie question... :(
It's not a secret anymore!