利用PreparedStatement对象进行批量操作(executeBatch),报内存溢出异常(OutOfMemoryError)
rs是一个结果集对象,由一个查询语句得出。记录数100000余。........StringbaseSql="insertintotableA(ColA,ColB,Col...
rs 是一个结果集对象,由一个查询语句得出。记录数100000余。
........
String baseSql = "insert into tableA(ColA,ColB,ColC) values(?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(baseSql);
int flag = 0;
while(rs.next()){
pstmt.setString(1,rs.get(1));
pstmt.setString(2,rs.get(2));
pstmt.setString(3,rs.get(3));
pstmt.addBatch();
flag++;
if(flag % 10000 == 0){
pstmt.executeBatch();
System.out.println("====" + flag);
}
}
pstmt.executeBatch();
conn.commit();
.....
程序运行结果显示,当执行第8个批次操作的时候报错,内容如下:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
at java.util.Vector.ensureCapacityHelper(Vector.java:226)
at java.util.Vector.addElement(Vector.java:573)
at oracle.jdbc.driver.OracleResultSetCacheImpl.put(OracleResultSetCacheImpl.java:67)
at oracle.jdbc.driver.ScrollableResultSet.putCachedValueAt(ScrollableResultSet.java:1951)
at oracle.jdbc.driver.ScrollableResultSet.cacheRowAt(ScrollableResultSet.java:1595)
at oracle.jdbc.driver.ScrollableResultSet.isValidRow(ScrollableResultSet.java:1571)
at oracle.jdbc.driver.ScrollableResultSet.next(ScrollableResultSet.java:301)
我想知道问题到底出在了哪里!!!明明是分批操作,而且前几批是成功了的啊!如果哪个对象惹得祸,它又是如何导致异常发生的? 展开
........
String baseSql = "insert into tableA(ColA,ColB,ColC) values(?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(baseSql);
int flag = 0;
while(rs.next()){
pstmt.setString(1,rs.get(1));
pstmt.setString(2,rs.get(2));
pstmt.setString(3,rs.get(3));
pstmt.addBatch();
flag++;
if(flag % 10000 == 0){
pstmt.executeBatch();
System.out.println("====" + flag);
}
}
pstmt.executeBatch();
conn.commit();
.....
程序运行结果显示,当执行第8个批次操作的时候报错,内容如下:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
at java.util.Vector.ensureCapacityHelper(Vector.java:226)
at java.util.Vector.addElement(Vector.java:573)
at oracle.jdbc.driver.OracleResultSetCacheImpl.put(OracleResultSetCacheImpl.java:67)
at oracle.jdbc.driver.ScrollableResultSet.putCachedValueAt(ScrollableResultSet.java:1951)
at oracle.jdbc.driver.ScrollableResultSet.cacheRowAt(ScrollableResultSet.java:1595)
at oracle.jdbc.driver.ScrollableResultSet.isValidRow(ScrollableResultSet.java:1571)
at oracle.jdbc.driver.ScrollableResultSet.next(ScrollableResultSet.java:301)
我想知道问题到底出在了哪里!!!明明是分批操作,而且前几批是成功了的啊!如果哪个对象惹得祸,它又是如何导致异常发生的? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询