JDBI:使用 kotlin 查询字符串列
JDBI: querying a string column with kotlin
我在 SQL table myTable
中有一列 title
。
使用 Kotlin 和 JDBI,我将如何获取此 table 中的所有不同条目?
这是我目前尝试过的方法:
val jdbi = Jdbi.create("...url", "...user", "...password")
fun getTitles(): List<String> = jdbi.withHandleUnchecked { handle ->
handle.createQuery("select distinct(title) from myTable;")
.mapTo(String.javaClass)
.list()
但是,这给了我以下异常:
A bean, Companion was mapped which was not instantiable (cannot find appropriate constructor)
这里出了什么问题?
显然,String.javaClass
不是我想要的(因为它的类型与要求的类型不同)。是String::class.java
.
我在 SQL table myTable
中有一列 title
。
使用 Kotlin 和 JDBI,我将如何获取此 table 中的所有不同条目?
这是我目前尝试过的方法:
val jdbi = Jdbi.create("...url", "...user", "...password")
fun getTitles(): List<String> = jdbi.withHandleUnchecked { handle ->
handle.createQuery("select distinct(title) from myTable;")
.mapTo(String.javaClass)
.list()
但是,这给了我以下异常:
A bean, Companion was mapped which was not instantiable (cannot find appropriate constructor)
这里出了什么问题?
显然,String.javaClass
不是我想要的(因为它的类型与要求的类型不同)。是String::class.java
.