aspose file tools*
The moose likes JDBC and the fly likes Question on resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Question on resultset" Watch "Question on resultset" New topic
Author

Question on resultset

Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Oct 11, 2000
Posts: 1135

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on resultset