This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Confusion about JDBC in Java 8

 
Greenhorn
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?
 
Bartender
Posts: 1175
38
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: 39530
776
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!)
 
No holds barred. And no bars holed. Except this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!