无法将binary(16)类型的uuid添加到sql中

8oomwypt  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(160)

完全按照这个问题和解决办法去做,我还是解决不了这个问题。我仍然得到“第1行'id'列的数据太长”

public static byte[] asBytes(UUID uuid) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return bb.array();
  }

  UUID id= UUID.randomUUID();
  InsertQueryBuilder runner = new InsertQueryBuilder("test_table")
        .addField("id", asBytes(id));

       return getConnection()
      .flatMap(connection -> runner.run(connection)
        .doOnTerminate(connection::close))

从这个答案我知道16字节是32个十六进制数字。因此,如果我将列类型更改为binary(32),那么我不会得到任何错误,并且id会成功地写入db。
我试图保持bytebuffer bb大小为8,但后来我得到;
缓冲区溢出异常
我错过了什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题