在此代码中:
public static void viewTable(Connection con, String dbName)
throws SQLException {
Statement stmt = null;
String query =
"select COF_NAME, SUP_ID, PRICE, " +
"SALES, TOTAL " +
"from " + dbName + ".COFFEES";
try {
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String coffeeName = rs.getString("COF_NAME");
int supplierID = rs.getInt("SUP_ID");
float price = rs.getFloat("PRICE");
int sales = rs.getInt("SALES");
int total = rs.getInt("TOTAL");
System.out.println(coffeeName + "\t" + supplierID +
"\t" + price + "\t" + sales +
"\t" + total);
}
} catch (SQLException e ) {
JDBCTutorialUtilities.printSQLException(e);
} finally {
if (stmt != null) { stmt.close(); }
}
}
特别是这段代码:
ResultSet rs = stmt.executeQuery(query);
此语句是否将所有行检索到ResultSet,或部分检索?我需要在Hibernate中加载一个包含500万行的表,并且有一个OutofMemory错误。它失败了:
List<Term> terms = em.createQuery(criteria).getResultList();
我需要在Mysql&amp;中找到一种方法。 Hibernate加载此表时出现内存问题。感谢。