I try use ScalikeJDBC for access to array in PostgreSQL 9.4. DDL:
create table itab (
code varchar primary key,
group_list varchar[]
);
A simple case class and loader are defined in Scala application.
case class Item(code: String, groupSet: List[String])
trait loader {
def loadAllItems: List[Item] = {
insideReadOnly { implicit session =>
sql"select CODE, GROUP_LIST from ITAB"
.map(e => Item(
e.string("code"),
e.array("group_list").asInstanceOf[Buffer[String]]
)).list.apply()
}
}
}
When I run an application I get runtime exception
java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4Array cannot be cast to scala.collection.mutable.Buffer
How can I resolve it? Thanks. Hoviman.
Use rs.array("group_list").getArray.asInstanceOf[Array[String]]
It's just java.sql.Array underneath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With