展开全部
用bath,批量e68a84e8a2ad62616964757a686964616f31333332626666提交,成功是返回的记录条数,不等于提交的条数就回滚,有bath为什么不用bath,上了几百条不是要写死,大致修改了下,你对照再修改下:Connection conn = null;
PreparedStatement p;
try {
conn.setAutoCommit(false);
String sql = "insert into intact_message(STCD,TM,Message) values(?,?,?)";
p = conn.prepareStatement(sql);
p.setString(1, str[0]);
SimpleDateFormat sf = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
Date date = sf.parse(str[1]);
p.setTimestamp(2, new java.sql.Timestamp(date.getTime()));
p.setString(3, str[2]);
p.addBatch();
p.setString(1, str[0]);
SimpleDateFormat sf1 = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
Date date1 = sf1.parse(str[1]);
p.setTimestamp(2, new java.sql.Timestamp(date1.getTime()));
p.setString(3, str[2]);
p.addBatch();
int[] num = p.executeBatch();
if (num.length == 2) {
conn.commit();
} else {
conn.rollback();
}
} catch (Exception e) {
e.printStackTrace();
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
}