result set type is 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();

 

你可能感兴趣的:(jdk,Access)