我有一个表需要插入记录,id字段是主要的auto_increment字段,我不确定我应该使用什么隔离级别,这样当2个并发事务时不会创建具有相同id的记录在工作中?这是我的代码:
String query = "insert into InstrumentTable values(?,?,?,? )";
Connection con = null;
PreparedStatement prepedStatement = null;
try {
con = connectionPool.getConnection();
con.setAutoCommit(false);
prepedStatement = con.prepareStatement(query);
prepedStatement.setString(1, type);
prepedStatement.setInt(2, permissionLevel);
prepedStatement.setInt(3, slotTime);
prepedStatement.setString(4, description);
prepedStatement.executeUpdate();
con.commit();
}
感谢
答案 0 :(得分:0)
我认为任何隔离级别都可以,因为auto_increment字段应该注意不提供重复值。当然,您应该尝试至少使用READ_COMMITTED(并且某些数据库不支持较低的隔离级别)。