I have a column title
in a SQL table myTable
.
Using Kotlin and JDBI, how would I go about getting all the distinct entries in this table?
This is what I have tried so far:
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()
However, this gives me the following exception:
A bean, Companion was mapped which was not instantiable (cannot find appropriate constructor)
What's going wrong here?
Apparently, String.javaClass
is not what I want here (as it is a different type than is required). It is String::class.java
.