有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用类型_SCROLL u SENSITIVE时出现Java jdbc警告

这是从OCA/OCP Java®SE 7程序员I&;II学习指南(考试1Z0-803和1Z0-804)书籍:

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.

我不知道为什么设置type_SCROLL_usensitive类型的语句会导致将类型重置为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);

共 (1) 个答案

  1. # 1 楼答案

    请看这里: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.

    它接着说:

    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.

    好的,这些是特定于Oracle数据库的,但它显示了降级的示例