This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet Question

 
jacq carballo
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with the following command string?
1 command = "select field1, field2 from table1 " +
2 "select fld1, fld2 from table2";
3
4 rs.executeQuery(command);
5
6 field1 = rs.getString(field1);
7 field2 = rs.getString(field2);
8 fld1 = rs.getString(fld1);
9 fld2 = rs.getString(fld2);
I get an error on line 8 saying that fld1 is an invalid column name.
What is the fix to it?
TIA
jacq carballo
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post the stack trace from the error
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's two basic problems with your code, I think. One is that it's very dodgy to just string two select statements together like that. There's no guarantee what the database will do with it. I'd suggest doing each of the two selects as a separate query with a separate resultset.
The second problem is that you need to quote the names in your call to getString. The argument to getString is the name of the column, not a variable.
 
jacq carballo
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, yeah. I forgot to put the quotation marks.
Anyway, thanks for the tip of separating both select statements.
jacq carballo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic