Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to insert a series of values into a sql query using Java's postgresql jdbc4.

java.sql.Connection specifies a method to convert Object[] into java.sql.Array: conn.createArrayOf(String typeName, Object[] elements)

The only problem is, no matter what I try, it always returns null.

public Array makeQueryBigintArray(Object[] values) throws SQLException {
    Array result = conn.createArrayOf("bigint", values);
    // "result" is null at this point, but shouldn't be
    return result;
}

conn is retrieved through a working javax.sql.DataSource via dataSource.getConnection(). conn works for all our other database uses, but its createArrayOf() method always returns null.

I have tried both upper case "BIGINT" and lower case "bigint" for typeName, as per this question, to no avail.

When I dig through the debugger, I find that conn is a org.apache.commons.dbcp.PoolableConnection wrapping a org.postgresql.jdbc4.Jdbc4Connection.

If the feature wasn't supported by postgres/JDBC4, I would expect calling it to throw a SQLException indicating it's unsupported. No exception is thrown.

Any clue as to why it's returning null?

How can I fix it, or else, how can I pass in an array or List of values to a PreparedStatement?

share|improve this question
    
Are you using a recent JDBC 4(!) driver of PostgreSQL? It looks like it is implemented: github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/jdbc4/… (and has been for a few years now) –  Mark Rotteveel Dec 19 '14 at 7:33
    
Could you try with "int8"? "bigint" is just an alias of "int8" (but both should be used in this context). –  pozs Dec 19 '14 at 12:47
    
@MarkRotteveel We're using a build that is only 2 builds behind the most current PostgreSQL JDBC. That is, we are using build 1002, and build 1004 is the most current as of 12/19/14. I had similar thoughts that maybe it was a really old one, but it's recent. –  Martin Carney Dec 22 '14 at 18:01
    
Ok, but are you using the jdbc 4 build? Afaik, the jdbc 3 build doesn't have it. –  Mark Rotteveel Dec 22 '14 at 18:28
    
@MarkRotteveel Yeah, JDBC 4 standard, build 1002. –  Martin Carney Dec 22 '14 at 19:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.