Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on resultset

 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • 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?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic