Search code examples
javapostgresqljdbi

Postgres Integer[] store using JDBI


I want to store the arrayList into postgres database where the dataType is Integer[]. I am using JDBI.

Something like :

JDBI.handle().createStatement("insert into table(column_a) values (?)")
.bind(0, arrayList)
.executeAndReturnGeneratedKeys(IntegerColumnMapper.PRIMITIVE)
.first();

Solution

  • There is a method getConnection() in Handle class that returns object of Connection class which has a method createArrayOf("Integer", your list), this returns Array which you can use as bind parameter.

    .bind(parameterno, handle.getConnection().createArrayOf("Integer", your list);)