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

Resultset Parsing.

Rajesh Agarwal
Ranch Hand

Joined: Aug 01, 2005
Posts: 79
Hi All,

In the ResultSet I have the results of a query execution.
The ResultSet will not have column names as it is a read from the
DB2 database. So I have used getString(1) types...

Now for the same row, I need to read the value of the same column twice.
If I give getString(2) two times in the same loop, it is throwing
an exception.

Appreciate any help on how this can be done, apart from the
scrollable resultset thing.

Thanks in advance
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Just put the value of getString(2) in a String and second

time just read the String variable..No need to call

getString() again..

Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

What exception did you get ???


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Rajesh Agarwal
Ranch Hand

Joined: Aug 01, 2005
Posts: 79

Assume that I know all that, is there a way using JDBC.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33111

Your choices are:
1) Use a different driver - probably not practical for you
2) Return the column twice in the select clause - this is inefficient
3) Try using getString("name") - probably has same issue
4) Store as local variable as Sunil suggested

I recommend going with choice #4. It protects you against any other driver oddities that may arise.

What is the reason you don't want a local variable? JDBC is very closely tied to Java anyway.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Resultset Parsing.
It's not a secret anymore!