关于Mysql结果集过大的问题?

chg2008 2006-05-01 01:28:09
表里的记录有几百万条,直接取出
如下:
public ResultSet getRS() throws Exception {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = getConnection();
String query = "select * from user_month";
stmt = con.createStatement();
rs = stmt.executeQuery(query);
}
catch(Exception e){
e.printStackTrace();
}
return rs;
}
那么程序运行时会出现Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
那么应该怎么取才不会出现这类异常,谢谢?
...全文
162 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
f_acme 2006-05-01
  • 打赏
  • 举报
回复
select * from user_month
最好将*改为某些列名试下,一般情况不用取出所有的列吧
zx2002027 2006-05-01
  • 打赏
  • 举报
回复
分批读取试试
fosjos 2006-05-01
  • 打赏
  • 举报
回复
一般用String query = "select * from user_month limit ...";
总数用"select count(*) from user_month"计算

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧