public static void insertSong(List<Tone32> toneList){
Test23 t = new Test23();
try{
conn=t.getConn();
for(Tone32 tone : toneList){
String sql = "insert into tone (toneType,song,artist,price) values(?,?,?,?)";

pstm = conn.prepareStatement(sql);
pstm.setString(1, tone.getToneType());
pstm.setString(2, tone.getSong());
pstm.setString(3, tone.getArtist());
pstm.setDouble(4, tone.getPrice());

pstm.executeUpdate();
}
t.Close();
System.out.println("入库结束");
}catch(Exception e){
e.printStackTrace();
}
}向MYSQL 里插入数据  我的toneList里有28000左右的数据但是插入 12000多条的时候 抛异常Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:437)
at com.mysql.jdbc.Connection.clientPrepareStatement(Connection.java:2185)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4782)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4687)
at test.Test32.insertSong(Test32.java:121)
at test.Test32.main(Test32.java:145)

解决方案 »

  1.   

    java.lang.OutOfMemoryError: Java heap space不是MYSQL的问题,是JAVA的问题。建议你可以转到JAVA版问一下如果是C或C++,C#的话,你的这些  String sql, pstm  对象什么时候会被释放所占的内存空间?
      

  2.   

    已经解决了 在网上找的从Intalled JREs里修改;window->Preferences->Java->Installed JREs,选择当前的JRE,然后edit它;在新窗口里设置Default VM Arguments为 -Xms128M -Xmx512M即可