0

I am trying to use ActiveJDBC to properly convert an integer[] from my PostgreSQL database into the java equivalent int[]. I get the fetch done properly, but the object that is returned is weblogic.jdbc.wrapper.Array_org_postgresql_jdbc_PgArray. I have yet to find a way to convert that.

I have tried 2 different ways of accessing the data:

First, using the standard record.findFirst("id = ?", id) format. Because I have multiple schemas in my database, I added the @Table notation to my Model.

Second, I tried doing a record.findBySQL("select array from record where id = ?", id). I also tried array::integer[].

Each time I get back the PgArray type. I have searched for a way to convert this type into something else for use, but nothing has worked.

Is there a way to do this? Do I need to use a different way of data retrieval other than ActiveJDBC?

Ashish Tiwari
  • 2,168
  • 4
  • 30
  • 54
E Lopez
  • 3
  • 2

1 Answers1

0

JDBC defines java.sql.Array to handle array typed columns. PgArray is just the Postgres implementation of java.sql.Array.

Given the array object a you can call (Integer[])a.getArray() to get an Integer array from the JDBC array object (if the JDBC driver has decided that it will return you Integer objects and not some other Numbers). A helper method to extract the value and convert to int[] would probably be a good idea.

Don't know if activejdbc has support to do this conversion behind the scenes.

wero
  • 32,544
  • 3
  • 59
  • 84
  • I am unable to use the getArray() method. ActiveJDBC places all retrieved items into my Model and I retrieve them using: model.get("column"). There is no getArray() method associated with that. I have tried casting that to both Integer[] as well as PgArray, but both throw ClassCastExceptions. – E Lopez Jun 29 '16 at 12:52
  • I just found that solution on another post here. It worked successfully. Thanks! – E Lopez Jun 29 '16 at 12:59
  • when you get the array by calling `get("column")`, what Java type are you getting back? – ipolevoy Jun 29 '16 at 17:43
  • @ipolevoy The class returned was `weblogic.jdbc.wrapper.Array_org_postgresql_jdbc_PgArray` – E Lopez Jun 30 '16 at 13:25