开发者

isolation level on a transaction in JDBC with an an auto_incremement field

I have a table that I need to insert records into, the id field is a primary auto_increment field, I am not sure about what isolation level I should use such that no record will be created with the same id when 2 concurrent transactions are working? this is my code:

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);
         开发者_如何学Python   prepedStatement.setString(4, description);
            prepedStatement.executeUpdate();
            con.commit();
        }

thanks


I think any isolation level will do as the auto_increment field should take care of not providing repeated values. Of course, you should try to work at least with READ_COMMITTED (and some databases do not support lower isolation levels).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜