java中批量执行JDBC操作时如果要批量插入数据的话,用 addBatch()用法很方便,具体用法下例: sql = "INSERT INTO LOG_FILENAME(ID,FILENAME,CREATETIME) VALUES(2,?,sysdate)"; public void batchInsertFileNames(File[] files) throws SQLException { Connection conn = null; PreparedStatement pstmt = null; try { conn = dataSource.getConnection(); pstmt = (PreparedStatement) conn.prepareStatement(sql); Date date = new Date(); for (int i = 0; i < files.length; i++) { setParams(pstmt, files[i].getName(), date); } //下句执行后开始批量插入数据 pstmt.executeBatch(); } finally { DbUtils.close(pstmt); } } private void setParams(PreparedStatement pstmt, String fileName, Date date) throws SQLException { pstmt.setString(1, fileName); //addBatch();执行后暂时记录此条插入 pstmt.addBatch(); }