2

mysql 中的 INT(10) unsigned 最大限制为 4b+,当与行的 getLong 一起使用时,它会引发以下错误:

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
    at com.github.jasync.sql.db.RowData$DefaultImpls.getLong(RowData.kt:48) ~[jasync-common-0.9.23.jar:?]
    at com.github.jasync.sql.db.general.ArrayRowData.getLong(ArrayRowData.kt:5) ~[jasync-common-0.9.23.jar:?]
    at com.richdevt.hthookserver.repository.ProjectRepository.findProjectEnvironment(ProjectRepository.kt:29) ~[classes/:?]
    at com.richdevt.hthookserver.repository.ProjectRepository$findProjectEnvironment$3.invokeSuspend(ProjectRepository.kt) ~[classes/:?]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32) [kotlin-stdlib-1.3.21.jar:1.3.21-release-158 (1.3.21)]
    at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233) [kotlinx-coroutines-core-1.1.1.jar:?]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:163) [netty-common-4.1.33.Final.jar:4.1.33.Final]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java) [netty-common-4.1.33.Final.jar:4.1.33.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) [netty-common-4.1.33.Final.jar:4.1.33.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495) [netty-transport-4.1.33.Final.jar:4.1.33.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) [netty-common-4.1.33.Final.jar:4.1.33.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.33.Final.jar:4.1.33.Final]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152

为什么不能转换?

4

1 回答 1

2

类型INT(10) UNSIGNED为 int(4 字节)大小,无符号:Mysql 中 int(10) 的最大大小是多少

但是,Java 没有这种类型(即最大值大于 Java 的最大 int)。另一方面,从 MySQL 返回的类型是此处定义的 INT:https ://dev.mysql.com/doc/refman/8.0/en/integer-types.html没有关于无符号的附加信息。在这种情况下,jasync-sql将其转换为常规 Int 类型。更多细节在这里:https ://github.com/jasync-sql/jasync-sql/issues/102

作为这种情况的解决方法,可以像这里建议的那样进行扩大转换:将有符号整数转换为无符号长整数的最佳方法?

于 2019-03-14T10:05:00.553 回答