• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Resultset Parsing.

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 824
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exception did you get ???

Shailesh
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sunil,

Assume that I know all that, is there a way using JDBC.
 
author & internet detective
Posts: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic