gpt4 book ai didi

使用 TYPE_SCROLL_ SENSITIVE 时的 Java jdbc 警告

转载 作者:行者123 更新时间:2023-12-01 10:37:05 25 4
gpt4 key购买 nike

这引自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_ SENSITIVE 类型的语句会导致将类型重置为 TYPE_FORWARD_ONLY,我是否遗漏了什么?

如上所述,此代码会将类型设置回 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);

最佳答案

请参见此处: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 数据库特定的,但它显示了降级的示例。

关于使用 TYPE_SCROLL_ SENSITIVE 时的 Java jdbc 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34621121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com