File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes FORWARD_ONLY Resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "FORWARD_ONLY Resultset" Watch "FORWARD_ONLY Resultset" New topic
Author

FORWARD_ONLY Resultset

MaheshS Kumbhar
Ranch Hand

Joined: Sep 24, 2009
Posts: 188
I read in JDBC doc on http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/resultset.html#1003004

For maximum portability with forward only result sets, values should be retrieved from left to right, and column values should be read only once. With scrollable result sets, however, there are no such restrictions.

Does this mean we cant read column value more than once from FORWARD_ONLY ResultSet?


I am slow but sure
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
I don't think so. Resultset is nothing but a cursor to your dataset at database layer. As long as you are on that row, you should be able to read that particular column multiple times, but once you moved to next, you can not go back if its FORWARD_ONLY.


love your job and not your company;
...because you never know when your company will stop loving you!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

you should be able to read that particular column multiple times
Hi,
are you certain of this?


OCUP UML fundamental and ITIL foundation
youtube channel
Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
Hi All,

java version : 1.5.0_06
jdbc driver : ojdbc14dms.jar
database : Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi


Output:


No exception!

Regards,

Fatih.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

You are lucky.
http://java.sun.com/docs/books/tutorial/jdbc/basics/retrieving.html
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.


In this case, it went wrong.
Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
Yes, you are right. After I saw your post, I remember facing this issue myself with my older 8i database.
I suppose underlying jdbc implementation has improved jdbc specs

Regards,

Fatih.
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
so does it mean that Oracle 10g driver has removed this shortcoming? But I guess as per jdbc3.0 spec, reading a field multiple times should be supported, though I am not sure.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

I wonder about this. You can retrieve column data by column number, but you can also retrieve (as their examples show) by column name. We did a lot of that under Oracle 8 and I don't recall ever having to specify named-based retrieval in the order of the column numbers. And, in, fact, being forced to do so would remove one of the primary advantages of name-based retrieval: independence of the table's column ordering.

Unless you've got really wide columns, it would generally make more sense for the entire row to be retrieved and cached at once, so I'd expect column-ordering issues to be mostly a safety precaution.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

I never had issues with reading columns in a different order than their sequence in the select statement.
But I have had issues when trying to read a column's value twice from a RecordSet. That is the reason why I remembered the quote I posted earlier in this thread.

Unfortunately, that is how far my memory goes. Don't remember database make, version or driver anymore (I'm in my 40s).
The other Rancher that had the same issue doesn't mention what database or driver he used either. I'm going to ask it.
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
Jan, you have great energy at this age to hook up to ranch and great memory as well!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
manoj r patil wrote:Jan, you have great energy at this age . . .
At this age??

Cheeky so-and-so! Jan is a mere child.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FORWARD_ONLY Resultset