更新mysql驅動5.1-47後出現錯誤:Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYjava
java.sql.SQLException: Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate(), Statement.executeLargeUpdate() or Connection.prepareStatement().mysql
通過檢查發現從5.1.7版本以後的mysql-connector增長了返回GeneratedKeys的條件,若是須要返回GeneratedKeys,則PreparedStatement須要顯式添加一個參數Statement.RETURN_GENERATED_KEYS,以下:sql
connection = JDBCUtil.getConnection();
preparedStatement = connection.prepareStatement(sql.toString(),Statement.RETURN_GENERATED_KEYS);ide