JDBC中具有自动递增字段的事务的隔离级别

JDBC中具有自动递增字段的事务的隔离级别,jdbc,Jdbc,我有一个需要插入记录的表,id字段是一个主要的自动增量字段,我不确定应该使用什么隔离级别,以便在两个并发事务工作时不会创建具有相同id的记录?这是我的代码: String query = "insert into InstrumentTable values(?,?,?,? )"; Connection con = null; PreparedStatement prepedStatement = null; try { c

我有一个需要插入记录的表,id字段是一个主要的自动增量字段,我不确定应该使用什么隔离级别,以便在两个并发事务工作时不会创建具有相同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();
        }

谢谢

我认为任何隔离级别都可以,因为auto_increment字段应该注意不提供重复值。当然,您至少应该尝试使用READ_COMMITTED,并且一些数据库不支持较低的隔离级别