Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resultset Parsing.

 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 824
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just put the value of getString(2) in a String and second

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

getString() again..
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exception did you get ???

Shailesh
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil,

Assume that I know all that, is there a way using JDBC.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh,
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic