2

I'm trying to bind a prepared statement parameter which is a array PostgreSQL. Here's an example Query:

prepareStatement("UPDATE " + emailsFromDb.get(i) +  " SET columne =testvalue '," + id + "' WHERE id IN (?)" );

I read from txt file value as array this is code read from txt

Scanner inFile1 = new Scanner(new File("file.txt"));
while(inFile1.hasNext()) {
    sb.append(inFile1.nextLine());
}
String[] testArray = sb.toString().split(", ");

and prepare the array in sql

Array bulkarr=  connector.createArrayOf("INT", testArray);
pr.setArray(1, bulkarr);

pr.executeUpdate();

and the result I have this error

2017-11-02 17:12:58 --ERROR-ApplicationErrorMessage : 
org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = integer[]
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 106

I need to update with where in array postgres

1 Answer 1

1

The IN operator does not support arrays, you need to use ANY

WHERE id = ANY (?)

then you can pass an array, through setArray()


Unrelated, but: If you are using a PreparedStament you should pass all values through that. Concatenating input into a SQL string is a really, really bad idea.

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

1 Comment

what can I do I need to update bukl from txt whta tis the best way ??

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.