Use JDBI to get Postgres Array Data

2019-05-26 11:19发布

问题:

I have a java program using JDBI (a JDBC wrapper) to access a PostgreSQL database. One of the columns is of the array data type (mycolumn integer[]).

What the heck to I use in my mapper class? I thought resultSet.getArray("mycolumn") would be the right thing to do, but I'm not sure how to get the data out of the java.sql.Array object that gets returned.

Any hints or good links on how to do this?

回答1:

        Array array = resultSet.getArray("mycolumn");
        return nonNull(array) ? (Integer[])array.getArray() : null ;


标签: java jdbc jdbi