Aladdin
Aladdin

Reputation: 1337

Java jdbc warning when using TYPE_SCROLL_ SENSITIVE

This is quoted from OCA/OCP Java® SE 7 Programmer I & II Study Guide (Exams 1Z0-803 & 1Z0-804) book :

For example, suppose that we mistakenly set the result set type to TYPE_SCROLL_ SENSITIVE when creating a Statement object. This does not create an exception; instead, the database will handle the situation by chaining a SQLWarning to the Connection object and resetting the type to TYPE_FORWARD_ONLY (the default) and continue on.

I don't know why setting the statement of type TYPE_SCROLL_ SENSITIVE will cause resetting the type to TYPE_FORWARD_ONLY, am I missing anything?

As per above this code will setting the type back to TYPE_FORWARD_ONLY

Connection conn =
DriverManager.getConnection("jdbc:derby://localhost:1527/BookSellerDB",
"bookguy", "$3lleR");
Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String query = "SELECT * from Book WHERE Book.Format = 'Hardcover'";
ResultSet rs = stmt.executeQuery(query);

Upvotes: 0

Views: 148

Answers (1)

Andreas
Andreas

Reputation: 159114

See here: https://docs.oracle.com/cd/A87860_01/doc/java.817/a83724/resltse2.htm#1018253

To produce a scroll-sensitive result set:

  • A query cannot use "SELECT *". (But see the workaround below.)
  • A query can select from only a single table.
  • A query cannot use ORDER BY.

It continues:

If the specified result set type or concurrency type is not feasible, the Oracle JDBC driver uses the following rules in choosing alternate types:

  • If the specified result set type is TYPE_SCROLL_SENSITIVE, but the JDBC driver cannot fulfill that request, then the driver attempts a downgrade to TYPE_SCROLL_INSENSITIVE.
  • If the specified (or downgraded) result set type is TYPE_SCROLL_INSENSITIVE, but the JDBC driver cannot fulfill that request, then the driver attempts a downgrade to TYPE_FORWARD_ONLY.

Ok, those are Oracle Database specific, but it shows an example of downgrading.

Upvotes: 1

Related Questions