标签:
getFetchSize() returns the number of records that database fetch to your applicaton at a time. By default, the fetch size is 10. Let‘s assume that your query result contains 100 records. It would takes 10 round trips to transfer 100 records to your application (10 x 10 = 100). GetFetchSize() does not return the number of records in the resultset. If you need to ensure that there is at least one record.
http://www.coderanch.com/t/299924/JDBC/databases/workings-ResultSet-getFetchSize
getFetchSize()方法不是获得记录数,而是获得每次抓取的记录数,默认是0,也就是说不限制。可以用setFetchSize()来设置,而getFetchSize()是用来读出那个设置值。设置为正整数之后,ResultSet每次抓取的最多纪录数就有了上限,而不是所有符合条件的记录。
如果你是想获得符合条件的记录数目,最少有3种方法
1.
count=0;
while(resultSet.next()){
count++;
}
2.
resultSet.last();
count=resultSet.getRow();
3.
如楼上所述
String sql = "select count(*) totalCount from gonglue";
count=rs.getInt("totalCount");
http://blog.chinaunix.net/uid-26284395-id-3158087.html
这是JDBC2.0 新增的一个方法,其目的是对 现有 的 结果集 进行增强功能
(详细可以参考jdbc2。0 的文档)
Connection con = DriverManager.getConnection(
"jdbc:my_subprotocol:my_subname");
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stmt.setFetchSize(25);
ResultSet rs = stmt.executeQuery(
"SELECT * FROM TALBE");
(创建可滚动结果集,该结果集是可更新的且对于更新敏感。它请求一次从数据库取出 25 个数据行)。
当然你可以用它来实现分页。
定位可以使用
ResultSet.absolute(5);(就表明定位于第无条记录。)
之后所有的对ResultSet的操作,都是从第5条记录开始。
(注,以上都是JDBC2.0才有的,当然3.0也包含了。)
对于分页技术,有好多方法。
通过absolute,来定位,比较好。我现在把分页从客户端实现。
http://www.cnblogs.com/jinanwangzhanjianshe/archive/2008/06/23/2472504.html
标签:
原文地址:http://www.cnblogs.com/softidea/p/4397145.html