0

ArrayList temp2 = new ArrayList();

Im filling this arraylist with longs.

When i am trying to insert this into the postgresql, i use the following:

UPDATE pb1plnitm SET parents_pb1plnitm_unid = ARRAY[?] WHERE pb1plnitm_unid = ?", temp2, xmlForm.getFieldValueLong("uniqueid"));

Using JDBC template. But when i try to run this code it gives a error on the "ARRAY[?]". But if temp2 is a single number like: 1253214, it works. Does anyone have an idea?

My error is:

PreparedStatementCallback; bad SQL grammar [UPDATE pb1plnitm SET parents_pb1plnitm_unid = ARRAY[?] WHERE pb1plnitm_unid = ?]; nested exception is org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of [Ljava.lang.Long;. Use setObject() with an explicit Types value to specify the type to use.

1 Answer 1

2

as mentioned in error description, make use of setObject() method

For Example:

Array sqlArray = conn.createArrayOf("text", anyArray);
    pstmt.setArray(1, sqlArray);
    pstmt.executeUpdate();
Sign up to request clarification or add additional context in comments.

1 Comment

You also need to remove the array[?] part and only use SET parents_pb1plnitm_unid = ?

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.