简体   繁体   English

DatabaseMetaData接口不起作用?

[英]DatabaseMetaData interface does not work?

I am trying the method of this interface explained here in this tutorial: 我正在尝试教程中在说明的此接口的方法:

Here I go: 我来啦:

DatabaseMetaData dm = con.getMetaData();
System.err.println(dm.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE));

I know it supports the TYPE_SCROLL_SENSITIVE type. 我知道它支持TYPE_SCROLL_SENSITIVE类型。 as I am using it and it works. 当我使用它,它的工作原理。 However the method above reported returns false. 但是,上面报告的方法返回false。 Have you ever tried using this method? 您是否尝试过使用这种方法? If yes does it work properly? 如果是,它是否可以正常工作? Thanks in advance. 提前致谢。

PS: The same happens with the other 2 types of ResultSets ( TYPE_SCROLL_INSENSITIVE and TYPE_FORWARD_ONLY ). PS:其他两种类型的TYPE_FORWARD_ONLYTYPE_SCROLL_INSENSITIVETYPE_FORWARD_ONLY )也是如此。 Considering that TYPE_FORWARD_ONLY is the default type it's a little bit strange that I get false in all three cases. 考虑到TYPE_FORWARD_ONLY是默认类型,这三种情况下我都为false ,这有点奇怪。 UPDATE: I am using JDBC-Mysql drivers; 更新:我正在使用JDBC-Mysql驱动程序。

The implementation in MySQL Connector/J 5.1.21 is: MySQL Connector / J 5.1.21中的实现为:

public boolean supportsResultSetType(int type) throws SQLException {
    return (type == ResultSet.TYPE_SCROLL_INSENSITIVE);
}

However a quick look at the rest of the implementation suggests that MySQL also supports the other types. 但是,快速浏览一下其余的实现则表明MySQL还支持其他类型。

Assuming you mean the Connector/J driver (there is more than one JDBC driver for MySQL), from the MySQL Connector/J JDBC implementation notes : 假设您指的是MySQL Connector / J JDBC实施说明中的Connector / J驱动程序(MySQL有多个JDBC驱动程序):

  • "MySQL does not support SQL cursors, and the JDBC driver doesn't emulate them", and “ MySQL不支持SQL游标,并且JDBC驱动程序不模拟它们”,以及
  • "By default, ResultSets are completely retrieved and stored in memory." “默认情况下,将完全检索结果集并将其存储在内存中。”

Since TYPE_SCROLL_SENSITIVE , TYPE_SCROLL_INSENSITIVE , and TYPE_FORWARD_ONLY usually indicate cursor types, then the statement that the driver doesn't even attempt to emulate them may explain why supportsResultSetType(...) returns FALSE for all values. 由于TYPE_SCROLL_SENSITIVETYPE_SCROLL_INSENSITIVETYPE_FORWARD_ONLY通常指示游标类型,因此驱动程序甚至不尝试模拟它们的声明可能解释了为什么supportsResultSetType(...)对所有值都返回FALSE。 With the default behavior of holding the entire result set in memory, forward-only or scrolling modes would be irrelevant. 由于默认的行为是将整个结果集保存在内存中,因此仅前进或滚动模式将是无关紧要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM