JDBC向sql server插入50万条数据出现:ava.lang.OutOfMemoryError: Java heap space

07-08-27 wolf00781

不知道甚么原因,但是插入15万就可以并且在40秒内完成,我的逻辑是这样的

PreparedStatement ps =conn.prepareStatement( "INSERT into code values (?,?)");

Date t=(Calendar.getInstance()).getTime();

System.out.print("循环开始"+t);

Set s=new HashSet();

for (int n = 0; n < 899999; n++) {

Long aa=Math.round((Math.random()*899999)+100000);

s.add(aa);

}

System.out.println("长度"+s.size());

Date tt=(Calendar.getInstance()).getTime();

System.out.print("插入开始"+tt);

Iterator iterator=s.iterator();

while(iterator.hasNext())

{

ps.setObject(1, iterator.next());

ps.setString(2, "0");

ps.addBatch();

System.out.print("技术器"+count);

//iterator.remove();

}

ps.executeBatch();

Date ttt=(Calendar.getInstance()).getTime();

System.out.print("结束"+ttt);

zjy0009
2007-08-28 10:38

899999个随机数都被你放在set中,当然会内存溢出.