啊,好古老的一个问题。。。 第二次出错的原因,是因为你创建Statement的时候,没有指定结果集(游标)模式! createStatement(int resultSetType, int resultSetConcurrency) resultSetType 就是结果集模式,取值范围是: ResultSet.TYPE_FORWARD_ONLY: cursor may move only forward. ResultSet.TYPE_SCROLL_INSENSITIVE: scrollable but generally not sensitive to changes to the data that underlies the ResultSet. ResultSet.TYPE_SCROLL_SENSITIVE: scrollable and generally sensitive to changes to the data that underlies the ResultSet. 从性能考虑,缺省情况下,结果集模式为 TYPE_FORWARD_ONLY,这种情况下,只能向前读取;字段和行集都是如此。 不过这个也是老JDBC的问题了,话说楼主还在用JDBC2.0 ? |
#13 得分:0回复于: 2012-08-09 13:36:11
对了,楼主可以做个实验,老版的JDBC,下面这么执行也会报错:
a = rs.getInt(2); // 先大下标 b = rs.getInt(1); // 再小下标 顺序正确则不会报错。 |
|
http://bbs.csdn.net/topics/390167395