boolean isSupportBatchUpdates(Connection conn) DatabaseMetaData dbm = con.getMetaData(); if(dbm.supportBatchUpdates()) return true; //notice: catch SQLException,AbstractMethodError return false;
int[] batchUpdate(String[] sql) //make sure sql is not null!!! int res = new int[sql.length]; if(isSupportBatchUpdates(conn)){ for(int i = 0;i stmt.addBatch(sql[i]); res = stmt.executeBatch(); } else { for(int i = 0 ;i if(!stmt.execute(sql[i])) res[i] = stmt.getUpdateCount(); else throw new .... } } return res;
|