当前位置: 代码迷 >> Java Web开发 >> 批量插入20w条数据,长事务有关问题
  详细解决方案

批量插入20w条数据,长事务有关问题

热度:26   发布时间:2016-04-17 17:07:32.0
批量插入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)      
  相关解决方案