批量插入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;
&n