aspose file tools*
The moose likes JDBC and the fly likes ResultSet Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet Question" Watch "ResultSet Question" New topic
Author

ResultSet Question

jacq carballo
Ranch Hand

Joined: Feb 10, 2002
Posts: 42
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

Joined: Dec 06, 2001
Posts: 138
can you post the stack trace from the error


Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
jacq carballo
Ranch Hand

Joined: Feb 10, 2002
Posts: 42
Oh, yeah. I forgot to put the quotation marks.
Anyway, thanks for the tip of separating both select statements.
jacq carballo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet Question