• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on resultset

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please explain what is the root cause of the below problem?



From the link Retrieving from resultset, I got the below info..

Using the getXXX Methods

The ResultSet interface declares getter methods (getBoolean, getLong, and so on) for retrieving column values from the current row. Your application can retrieve values using either the index number of the column or the name of the column. The column index is usually more efficient. Columns are numbered from 1. For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.

So, Is my code failing because I ma using getXXX method more than once for the same column? I know for a fact that using getXXX method on the same column multiple times doesnt solve any purpose since it can cause performance issues. But leaving performance aside, the piece of code which is not working should be working fine isnt it?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sripathi Krishnamurthy:
Can someone please explain what is the root cause of the below problem?

For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.



When we read the column, the pointer advance to the next column and if there are no more rows to read for that column , exception is thrown !
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sagar Rohankar:


When we read the column, the pointer advance to the next column and if there are no more rows to read for that column , exception is thrown !



I am afraid thats not the case here. Please look into the code. I am using the method resultSet.getClob(10). So it always tries to fetch from 10th column. The pointer doesnt move to next column automatically.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sripathi Krishnamurthy:


I am afraid thats not the case here. Please look into the code. I am using the method resultSet.getClob(10). So it always tries to fetch from 10th column. The pointer doesnt move to next column automatically.



No , Its fetch column number 10, not 10th row and to help my answer here is the quote from your above post ..

From the link Retrieving from resultset, I got the below info..

Using the getXXX Methods

The ResultSet interface declares getter methods (getBoolean, getLong, and so on) for retrieving column values from the current row. Your application can retrieve values using either the index number of the column or the name of the column. The column index is usually more efficient. Columns are numbered from 1. For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.

 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sripathi,
I guess to really understand why your code is failing, you'd have to look at the code of the JDBC driver you are using.
Maybe you have uncovered a bug?
Even in the code that you claim works, you are calling "getClob()" multiple times -- unless I am missing something.
In any case, it's an academic question since, as you claim, it is better coding style to call "getClob()" once and store its result in a variable, right?

Good Luck,
Avi.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic