自己开发了一个测试小程序?通过client去存取Mysql数据库.
最后执行程序出现OutOfMemoryError错误。请问各位高手如何解决这种问题?难道就是加大内存吗?把情况各高手们介绍先:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
数据库表的格式和记录数如下:
mysql> desc tx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | varchar(20) | YES  |     | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select count(*) from tx;
+----------+
| count(*) |
+----------+
|   637824 |
+----------+mysql> select * from tx limit  4,15;
+-------+-------------+
| id    | name        |
+-------+-------------+
| 100   | String100   |
| 10000 | String10000 |
| 10001 | String10001 |
| 10002 | String10002 |
| 10003 | String10003 |
| 10004 | String10004 |
| 10005 | String10005 |
| 10006 | String10006 |
| 10007 | String10007 |
| 10008 | String10008 |
| 10009 | String10009 |
| 10010 | String10010 |
| 10011 | String10011 |
| 10012 | String10012 |
| 10013 | String10013 |
+-------+-------------+
15 rows in set (0.00 sec)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&程序如下:
涉及两个类,一个是Model类,一个是操作类
public class Tx 
{
private String id;
private String name; public Tx(){
}
public Tx(String id,String name){
this.id=id;
this.name=name;
}
public void setId(String id){
this.id=id;
}
public void setName(String name){
this.name=name;
}

public String getId(){
return this.id;
}
public String getName(){
return this.name;
}
public static void main(String[] args) 
{
System.out.println("Hello World!");
}
}import java.sql.*;
import com.mysql.jdbc.Driver;
import java.util.*;class StringPerfB
{
public static void main(String[] args) throws SQLException,ClassNotFoundException
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/test";
String q="select * from tx"; System.out.println("******************************************");
Connection conn=DriverManager.getConnection(url,"root","");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery(q);
long start=System.currentTimeMillis();
String id=null;
String name=null;
Collection l=new ArrayList();
Tx tx=null;
int i=0;
try{
while(rs.next()){
id=rs.getString(1);
name=rs.getString(2);
tx=new Tx(id,name);
l.add(tx);
i++;
}
}catch(Exception e){
System.out.println(e.getMessage()+i);
}
long finish=System.currentTimeMillis();
System.out.println("Result A:"+(finish-start));
System.out.println("******************************************"); System.out.println("Hello World!");
}
}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
在执行程序的时候爆下面的错误
D:\j2sdk1.4.1_01\bin>javac StringPerfB.javaD:\j2sdk1.4.1_01\bin>java StringPerfB
******************************************
Exception in thread "main" java.lang.OutOfMemoryError&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
OK,全部情况已经说明,请给指教以下,当我把数据库表的记录删除一部分,剩余26万的时候,错误就不出现了。
我自己机器是P4 1.8G CPU,512内存,当执行程序的时候,看到内存冲378上升到440后,就出现了错误。