https://kotlinlang.org logo
Title
t

Tuang

10/19/2019, 1:15 PM
First of all my question may not be relate to Kotlin,, Why
QueryRunner().query()
return
Long
, is it depending on what Handler is using? For example my code is like this
val query = "SELECT COUNT(*) FROM goods_user_rel WHERE _goods_id = ?"
val count = QueryRunner().query(connection, query, ScalarHandler<Long>(), goodsId)
The first time i wrote
ScalarHandler<Int>()
and i got error something likes
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
Then i change
ScalarHandler<Int>()
to
ScalarHandler<Long>()
and it’s work but i have no idea why
Long
is return
d

deactivateduser

10/19/2019, 1:20 PM
I’m not really sure about QueryRunner, however coming from JPA, it is by specification that COUNT query must return data in LONG instead of INT. I believe it’s related in any way.
👍 1