当前位置:我的异常网» Java Web开发 » 批量插入20w条数据,长事务有关问题
批量插入20w条数据,长事务有关问题
www.myexceptions.net 网友分享于:2013-01-24 浏览:57次
批量插入20w条数据,长事务问题
我把所有要插入的数据放在Vector中,然后用prepareStatement来设置各个参数,相关代码如下:
db = new Database(dbURL, false);
conn = db.getConn();
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(preSql);
for (int j = 0; j < count; ++j)
{
try {
pstmt.clearBatch();
pstmt.clearParameters();
String[] tmp = ((String[])setConf.elementAt(j));
for (int i = 1; i <= tmp.length; ++i) {
pstmt.setString(i, tmp[i - 1]);
}
pstmt.addBatch();
tmpRets = pstmt.executeBatch();
} catch (SQLException e) {
Loger.log.error( "some operation about pstmt throw SQLException!\n " + e);
continue;
}
if (tmpRets != null)
文章评论