sqlserver2000中使用JDBC,addBatch方法,报内存溢出???
望高手指导!
异常:
Exception in thread "Thread-5" java.lang.OutOfMemoryError: Java heap space
at com.microsoft.jdbc.base.BaseParameters.<init>(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.addBatch(Unknown Source)
伪代码:list为数据集,list数据达到一定数据量后执行以下for循环插入数据,插入完成后清空list。再填充list,执行以下循环....往复循环此操作,当循环10次是没有问题的,大于10次后就报如上错误。
for ( list//数据集)
{
StringBuilder commandBuilder = new StringBuilder(
"INSERT INTO [" + flowType + "] VALUES(?" );
for ( ... )
{
commandBuilder.append( ", ?" );
}
commandBuilder.append( ")" );
pstmt = conn.getConnection().prepareStatement( command );
// 缓冲区中的数据量
int rowCount = 0;
for ( ... )
{
pstmt.setString( j , *** );
pstmt.addBatch();
if ( rowCount == 1000 )
{
conn.getConnection().setAutoCommit( false );
pstmt.executeBatch();
conn.getConnection().setAutoCommit( true );
pstmt.clearBatch();
rowCount = 0;
}
}
if ( rowCount != 0 )
{
conn.getConnection().setAutoCommit( false );
pstmt.executeBatch();
conn.getConnection().setAutoCommit( true );
}
list.clear();//数据集清空
} catch ( Exception e )
{
log.error( "", e );
} finally
{
try
{
if ( pstmt != null )
{
pstmt.close();
}
if ( conn != null )
{
conn.close();
}
} catch ( SQLException e )
{
log.error( "", e );
}
}
}