I'm trying to build an interface from Scala to JDBC callableStatements. For the most part, it's straightforward, except for Lists
.
I need to be able to take a Scala List
of some type, and convert it into a Java Array that can be passed to statement.setArray(type, array)
and I'm not having any luck (partly because I don't know Java and JDBC very well).
Here's what I'm trying to do:
for (parameter <- ps.parameters) {
case GPArrayIn(None, t) => callableStatement.setNull(index, t)
case GPIn(v: Some[_], Types.INTEGER) => callableStatement.setInt(index, v.get.asInstanceOf[Int])
case GPIn(v: Some[_], Types.VARCHAR | Types.LONGVARCHAR) => callableStatement.setString(index, v.get.asInstanceOf[String])
case GPArrayIn(v: Some[List[_]], Types.INTEGER) => callableStatement.setArray(Types.INTEGER, ???? )
case GPArrayIn(v: Some[List[_]], Types.VARCHAR | Types.LONGVARCHAR) => callableStatement.setArray(Types.VARCHAR, ???? )
...
It's pretty straightforward for simple values but when it comes to the setArray()
calls I'm stuck.
Any advice would be sorely appreciated. Been stuck on this for hours...