gpt4 book ai didi

java - JDBC ResultSet是应用级查询游标吗

转载 作者:可可西里 更新时间:2023-11-01 07:01:19 25 4
gpt4 key购买 nike

database cursor定义与 JDBC ResultSet API 惊人地相似。

但尽管所有这些相似,MySQL doesn't support database cursors :

MySQL does not support SQL cursors, and the JDBC driver doesn't emulate them, so setCursorName() has no effect.

那么,JDBC 实现是否是一种模仿数据库游标实现的数据访问规范,即使数据库并不真正支持这样的功能?

最佳答案

名字里有什么...

的确,ResultSet 和数据库游标在语义上是相似的。 The SQL:2011 standard指定:

A cursor is a mechanism by which the rows of a table may be acted on (e.g., returned to a host programming language) one at a time.

这听起来很像 ResultSet。再往下,SQL:2011 标准继续提到:

A cursor declaration descriptor and a result set descriptor have four properties: the sensitivity property (either SENSITIVE, INSENSITIVE, or ASENSITIVE), the scrollability property (either SCROLL or NO SCROLL), the holdability property (either WITH HOLD or WITHOUT HOLD), and the returnability property (either WITH RETURN or WITHOUT RETURN).

换句话说,这些功能都不是 JDBC(或 ODBC)规范团队“发明”的。它们确实以这种形式存在于许多 SQL 数据库实现中,并且与任何规范一样,上述许多功能在 SQL 实现中也是可选的。

您已经在 Jess 之前获得了关于 MySQL 部分的权威响应。 .我想补充一点,JDBC 与任何高级规范一样,有必需的部分和可选的部分。

查看 JDBC Spec ,我可以看到以下相关部分。

6.3 JDBC 4.2 API Compliance

A driver that is compliant with the JDBC specification must do the following:

[...]

It must implement the Statement interface with the exception of the following optional methods:

  • [...]
  • setCursorName
  • [...]

It must implement the ResultSet interface with the exception of the following optional methods:

  • [...]
  • getCursorName
  • [...]

ResultSet 类型的实现也是如此。在规范的更下方,您会发现:

The method DatabaseMetaData.supportsResultSetType returns true if the specified type is supported by the driver and false otherwise.

关于java - JDBC ResultSet是应用级查询游标吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32644665/

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