andy54321 发表于 2013-1-29 23:39:07

result属性之type_forward_only

connect=dataSource.getConnection();
Statement stmt=connect.createStatement();
ResultSet rs=stmt.executeQuery(strSql);
rs.last();
这样写之后会报rs.last()有错,后来看到last()方法:
Throws: SQLException - if a database access error occurs or the result set type is TYPE_FORWARD_ONLY后来查明原因果然是因为the result set type is TYPE_FORWARD_ONLY,查明的具体过程是:System.out.println(rs.getType());看到打印出来的结果是1003,后到JDK的src里面查到int TYPE_FORWARD_ONLY = 1003;这句话,说明the result set type is TYPE_FORWARD_ONLY。
那么解决办法就是要把the result set type 不要设成 TYPE_FORWARD_ONLY,后来在网上查到解决办法是:
connect=dataSource.getConnection();
Statement stmt=connect.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,  
                    ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery(strSql);
rs.last();
--------------------------
resultSet 方法很多,我也是在使用时用到rs.beforeFirst(),报错,才查找到的,看来API还是很有用的
 
页: [1]
查看完整版本: result属性之type_forward_only