• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Confusion about JDBC in Java 8

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am studying for Java 8 OCP (mainly Exam 1Z0-809). Now I have some confusion about JDBC in Java 8. In detail, I am confused about the createStatement(int resultSetType, int resultSetConcurrency) method of the Connection class.

The OCP book states that, when the specified ResultSet type and ResultSet concurrency mode are not supported, they may be downgraded. So, for example, if I specify ResultSet.TYPE_SCROLL_SENSITIVE for resultSetType, then I may get a Statement whose type is ResultSet.TYPE_SCROLL_INSENSITIVE.

But the official documentation of Java 8 seems to say something different. The documentation (https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#createStatement-int-int-) seems to say that, either a Statement with the specified ResultSet type and ResultSet concurrency mode will be returned, or an exception will be thrown. There is no downgrading.

So, which is correct?
Posts: 1275
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, welcome to the ranch ! Official documentation says that a SQLException is thrown whenever you try to invoke createStatement on a closed connection or you pass some int values that are not valid result set or cursor types ( i.e, you pass a resultset scroll type value as a resultset concurrency value, misplacing the parameters ); a SqlFeatureNotSupported exception if the required concurrency/scrolling policy aren't supported.Indeed, no mention of downgrading concurrency. I wonder if downgrading or not is implicitly left upon driver's and database's capabilities, even if I think it would be a unreliable behavior - at the end you're never sure about the real concurrency/scrolling type.
I'm pretty curious, let's add some flagsto your question and lt see if someone here can help.
author & internet detective
Posts: 40198
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it depends on your database driver. For example, the WebLogic/DB2 docs say:

oracle.com wrote:When the DB2 driver cannot support the requested result set type or concurrency, it automatically downgrades the cursor and generates one or more SQLWarnings with detailed information.

For the Java 8 OCP exam, you need to know that even if the code returns a Connection, it doesn't necessarily support the requested behavior.

For the Java 11 OCP exam, these flags aren't tested at all. (Whoo hoo!)
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic