关于Mysql结果集过大的问题?
表里的记录有几百万条,直接取出
如下:
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
那么应该怎么取才不会出现这类异常,谢谢?
问题点数:50、回复次数:3Top
1 楼fosjos(无聊的菜鸟程序员)回复于 2006-05-01 13:48:22 得分 20
一般用String query = "select * from user_month limit ...";
总数用"select count(*) from user_month"计算Top
2 楼zx2002027(http://www.netyi.net/in.asp?id=zx2002027)回复于 2006-05-01 15:53:24 得分 15
分批读取试试Top
3 楼f_acme(沧海一声笑)回复于 2006-05-01 20:14:23 得分 15
select * from user_month
最好将*改为某些列名试下,一般情况不用取出所有的列吧Top




