14

I'm trying to bind a prepared statement parameter which is a "multidimensional" PostgreSQL array. Here's an array example (column type is numeric[]):

{{1,10},{2,20}}

How do I bind a value like that using a prepared statement? I tried:

stmt.setObject(1, "{{1,10},{2,20}}", Types.ARRAY);

It didn't work:

Cannot cast an instance of java.lang.String to type Types.ARRAY

Any ideas?

2
  • something like this: stmt.setObject(1, new Integer[][] {{1,10},{2,20}}, Types.ARRAY)? Commented Sep 6, 2013 at 12:55
  • Doesn't work, I tried BigDecimal[][] as well. Commented Sep 6, 2013 at 13:10

1 Answer 1

19

Try something like this (untested):

                ------------------ your connection
                V
Array inArray = conn.createArrayOf("integer", new Integer[][] {{1,10},{2,20}});
stmt.setArray(1, inArray);

Links:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.