【发布时间】:2014-07-25 06:50:11
【问题描述】:
我想从包含数百万条记录的表中获取 50 条记录不使用限制
我关注了
private void createMYSQLConnection() throws SQLException {
CachedRowSet crs = new CachedRowSetImpl();
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydb",
"root", "root");
conn.setAutoCommit(false);
crs.setPageSize(100);
crs.setUsername("root");
crs.setPassword("Glass4#21");
crs.setCommand("SELECT * FROM trn_22_gouk_final_attendance");
crs.absolute(10);
crs.setFetchSize(10);
crs.execute(conn);
while (crs.next()) {
System.out.println(crs.getObject(1));
}
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
crs.close();
}
}
但它不起作用...... 任何建议
提前致谢
【问题讨论】:
-
我觉得你需要为此添加行号子句而不是获取计数
-
我不想根据以下内容编写特定于数据库的代码:java.avdiel.com/Tutorials/JDBCPaging.html 对于 mysql 我必须使用
limit对于 oracle 我必须使用rowNum但我想要独立于数据库的代码