0
我想获取从包含上百万的记录,而无需使用限制有没有办法取n个记录开始表单x行?
表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();
}
}
,但它不工作... 任何建议
谢谢提前
我觉得你需要添加行号子句,而不是取数 –
这可能会有所帮助:http://java.avdiel.com/Tutorials/JDBCPaging.html – Seb
我不想写代码是数据库特定的 根据:java.avdiel.com/Tutorials/JDBCPaging.html 对于MySQL我必须使用'极限'为甲骨文我必须使用'rowNum' 但我想代码独立于数据库 –