SQL server 读取某表行数以及报错ResultSet may only be accessed in a forward direction
来源:互联网 发布:企业资本结构优化 编辑:程序博客网 时间:2024/06/07 13:41
今天这个小小的问题难住我半天,(毕竟实习生水平)~~浪费光阴啊。不过总算解决了
ResultSet may only be accessed in a forward direction 这个错误的引起是jTDS驱动中的TYPE_SCROLL_INSENSITIVE只支持只读操作,TYPE_SCROLL_SENSITIVE支持Update操作,但不支持另外的Insert
所以我们prepareStatement()函数的第二个参数用 TYPE_SCROLL_SENSITIVE比较好
//某表的记录的行数
public int CountRowNumber(String tableName){
//参数为表名
try {
ResultSet rs = null;
String sql = "select * from "+tableName;
//Statement stmt = conn.createStatement();
PreparedStatement pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = pstmt.executeQuery();
rs.last();
return rs.getRow();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}
}
ResultSet may only be accessed in a forward direction 这个错误的引起是jTDS驱动中的TYPE_SCROLL_INSENSITIVE只支持只读操作,TYPE_SCROLL_SENSITIVE支持Update操作,但不支持另外的Insert
所以我们prepareStatement()函数的第二个参数用 TYPE_SCROLL_SENSITIVE比较好
//某表的记录的行数
public int CountRowNumber(String tableName){
//参数为表名
try {
ResultSet rs = null;
String sql = "select * from "+tableName;
//Statement stmt = conn.createStatement();
PreparedStatement pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = pstmt.executeQuery();
rs.last();
return rs.getRow();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}
}
0 0
- SQL server 读取某表行数以及报错ResultSet may only be accessed in a forward direction
- java.sql.SQLException: ResultSet may only be accessed in a forward direction.报错
- ResultSet may only be accessed in a forward direction
- ResultSet may only be accessed in a forward direction
- ResultSet may only be accessed in a forward direction 问题解决
- ResultSet may only be accessed in a forward direction
- ResultSet may only be accessed in a forward direction
- 解决 ResultSet may only be accessed in a forward direction 错误
- ResultSet may only be accessed in a forward direction Hibernate4异常解决方案
- 编译报错“a pointer to a bound function may only be used to call the function”的解决办法
- ibatis执行sybase存储过程报错Stored procedure 'proc_acctquery' may be run only in unchained transaction mode
- C++程序报错new types may not be defined in a return type?
- A Static Method Should Be Accessed In A Static Way
- Spark Q&A : Only one SparkContext may be running in this JVM
- Only one SparkContext may be running in this JVM
- 关于C++中报Error:new types may not be defined in a return type问题
- Recursion all file direction in a direction
- zabbix server 报错 zabbix server is not running: the information displayed may not be current
- 排序总结
- UVA - 11258 String Partition
- Swift调用OC之文件操作1
- 油田 uvaoj572
- JavaWeb监听器
- SQL server 读取某表行数以及报错ResultSet may only be accessed in a forward direction
- 猴子吃桃问题,每天吃一半多一个,吃了9天,求桃数
- hdu 5067
- 组播和IGMP
- Android Activity为什么要细化出onCreate、onStart、onResume、onPause、onStop、onDesdroy这么多方法让应用去重载?
- QML基本语法-----导入声明
- UVA - 10599 Robots(II)
- jquery 导航条 显示和自动隐藏div
- 03 常用UI控件