long _retId = -1;
        Connection con = null;
        try {
            con = queryRunner.getDataSource().getConnection();
            queryRunner.update(con, sql.toString(), val);
            Object _ret = queryRunner.query(con, "SELECT LAST_INSERT_ID() FROM " + getTableName(), new ScalarHandler());
            if (_ret instanceof BigInteger) {
                _retId = ((BigInteger) _ret).longValue();
            } else if (_ret instanceof Long) {
                _retId = (Long) _ret;
            } else {
                _retId = ((Integer) _ret).longValue();
            }
        } catch (SQLException e) {
            throw e;
        } finally {
            ConnectionUtils.closeConnection(con);
        }

注意:必须使用同一个Connection,否则会获取不到想要的结果

相关文章:

  • 2022-12-23
  • 2021-05-20
  • 2021-08-23
  • 2021-08-15
  • 2022-12-23
  • 2021-06-24
  • 2018-01-18
  • 2021-07-28
猜你喜欢
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
相关资源
相似解决方案