- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 JDBC 与 mysql-connector-java-6.0.2.jar 一起使用,并且除非我做错了什么,否则我认为 DatabaseMetaData.ownDeletesAreVisible 和 DatabaseMetaData.deletesAreDetected 实现在某种程度上彼此之间表现不一致。
以下是 JDBC 规范中关于 ownDeletesAreVisible 的规定:
"...如果删除的行被删除或被空行替换,DatabaseMetaData.ownDeletesAreVisible(int type) 方法将返回 true。如果 ResultSet 对象仍然包含删除的行,则返回 false,这意味着删除对于给定类型的 ResultSet 对象的更改不可见......”
关于deletesAreDetected:
“...如果从 ResultSet 对象中删除的行被删除,则该方法将返回 false;如果删除的行被空行或无效行替换,则该方法将返回 true...”
我将输出添加为注释:
import static java.sql.ResultSet.CONCUR_UPDATABLE;
import static java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE;
import java.sql.*;
public class Deletions {
public static void main(String[] args) throws SQLException {
try (Connection conn = DBUtils.getConnection();
Statement stmt = conn.createStatement(TYPE_SCROLL_INSENSITIVE, CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from book")) {
DatabaseMetaData dbmd = conn.getMetaData();
//prints false
System.out.println(dbmd.ownDeletesAreVisible(TYPE_SCROLL_INSENSITIVE));
// prints false. Controversy?
System.out.println(dbmd.deletesAreDetected(TYPE_SCROLL_INSENSITIVE));
// Prints everything including foo
printAll(rs);
// deletes foo
while (rs.next()) {
String title = rs.getString(2);
if (title.equalsIgnoreCase("foo")) {
rs.deleteRow();
}
}
// Prints everything without foo
printAll(rs);
}
}
private static void printAll(ResultSet rs) throws SQLException {
rs.beforeFirst();
while (rs.next()) {
System.out.println(rs.getString(2));
}
rs.beforeFirst();
}
}
最佳答案
这并不矛盾,JDBC 4.2 specification ,第 15.2.4.2 节说(强调我的):
After the method
deleteRow
has been called, the current row is deleted in the underlying data source. This deletion is visible as a change in the openResultSet
object if the row is either removed or replaced by an empty or invalid row.If the deleted row is removed or replaced by an empty row, the method
DatabaseMetaData.ownDeletesAreVisible(int type)
will returntrue
. It returnsfalse
if theResultSet
object still contains the deleted row, which means that the deletion is not visible as a change to ResultSet objects of the given type.[..]
If a
ResultSet
object can detect deletions, theResultSet
methodrowDeleted
returns true when the current row has been deleted and false when it has not. However,rowDeleted
also returnsfalse
if the ResultSet object cannot detect deletions. The methodDatabaseMetaData.deletesAreDetected(int type)
can be called to see whether aResultSet
object of the specified type can call the methodrowDeleted
to detect a deletion that is visible. The methoddeletesAreDetected
returnsfalse
if a row deleted from theResultSet
object is removed from it and true if the deleted row is replaced by an empty or invalid row.
这需要一些字里行间的阅读(并查看该部分中的示例代码),但这意味着 deletesAreDetected
only 在删除可见的情况下才有意义,它识别删除如何可见:行已被删除 (false
),或者替换为空行或无效行 (true
)。
因此,由于 ownDeletesAreVisible
返回 false
,deletesAreDetected
的结果对于“自己的”删除没有任何意义(除了“deletes are”)没有检测到');它可能对“其他”删除有意义,但我怀疑当您自己的删除不可见时其他删除是否可见。
关于java - DatabaseMetaData.ownDeletesAreVisible 与 DatabaseMetaData.deletesAreDetected 争议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38214241/
我将 JDBC 与 mysql-connector-java-6.0.2.jar 一起使用,并且除非我做错了什么,否则我认为 DatabaseMetaData.ownDeletesAreVisible
我是一名优秀的程序员,十分优秀!