• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Doubt about invoking absolute(0) on ResultSet (K&B7, chapter 15, page 883)

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chapter 15, page 883
boolean absolute(int row) description states: "Moving to row 0 moves the cursor to before the first row."
=> issuing rs.absolute(0) results in "java.sql.SQLException: Invalid argument(s) in call: absolute(0)" for me. Perhaps it is vendor implementation dependent?

(This post originated in the K&B7 errata thread)
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

J Deckarm wrote:boolean absolute(int row) description states: "Moving to row 0 moves the cursor to before the first row."
=> issuing rs.absolute(0) results in "java.sql.SQLException: Invalid argument(s) in call: absolute(0)" for me. Perhaps it is vendor implementation dependent?


ResultSet is an interface and as you know an interface is a contract, so it defines the behavior of every method. If you implement an interface, you must meet the contract; otherwise your implementation is not a valid one.

This is a snippet of the javadoc of the absolute() method of ResultSet

Java 7 API Specification, ResultSet wrote:If the row number specified is zero, the cursor is moved to before the first row.

So that's exactly what the study guide is stating. So I don't think it's a vender implementation thing, because then you would be using an invalid JDBC driver.

A little further in the javadoc of the absolute() method you can read

Java 7 API Specification, ResultSet wrote:SQLException - if a database access error occurs; this method is called on a closed result set or the result set type is TYPE_FORWARD_ONLY

So you can only invoke this method on a scrollable result set which is not closed (without getting an exception). So was the result set you used for testing a scrollable one or not? If you didn't provide any parameters when invoking Connection.createStatement(), the result set is TYPE_FORWARD_ONLY and the SQLException you got was expected behavior.

Hope it helps!
Kind regards,
Roel
 
J Deckarm
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did use a scrollable RS (TYPE_SCROLL_INSENSITIVE), actually I noticed this when playing with the RS navigation methods in the book with various arguments, and all seemed to work as described, except from absolute(0)

Per your suggestion regarding another of my questions (https://coderanch.com/t/655693/java-programmer-SCJP/certification/Calling-commit-rollback-autocommit-mode) I have checked this one as well with OJDBC 12, and there it seems to work correctly. Perhaps this is also something that has been made compliant in a later release only.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the study guide's point of view, it's reasonable (and even recommended) to explain what's mentioned in the javadoc for a method, because that's probably what you will be tested about on the actual exam Although not every driver seems to meet the contract defined by the JDBC interfaces, the javadoc of the absolute() method of ResultSet clearly states the cursor is moved to before the first row if zero is used as row number. So I think there's no need to add this one to the errata overview.
 
J Deckarm
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. However, given that there are apparently more than one similar issues, maybe a general remark would worth mentioning in this chapter, that not all versions of every vendor's JDBC implementation seems to be fully compliant with the contract.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

J Deckarm wrote:However, given that there are apparently more than one similar issues, maybe a general remark would worth mentioning in this chapter, that not all versions of every vendor's JDBC implementation seems to be fully compliant with the contract.


Agreed! Added to the errata overview.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic