I have prepared sql statement:
PreparedStatement insert_query = db.prepareStatement(String.format(INSERT_QUERY, table,
columns.toString(), placeholder));
System.out.println(insert_query);
Result:
INSERT INTO "article" (article_text, article_id, article_title) VALUES (?, ?, ?) RETURNING article_id
Next I create values list, set parameters and execure insert query:
ArrayList<String> values = new ArrayList<String>(); -- > is [New CONTENT, 4, New TITLE]
for (int i = 1; i <= values.size(); i++) {
insert_query.setString(i, values.get(i-1));
}
System.out.println(insert_query);
insert_query.executeUpdate();
I got an error:
INSERT INTO "article" (article_text, article_id, article_title) VALUES ('New CONTENT', '4', 'New TITLE') RETURNING article_id
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: column "article_id" is of type integer but expression is of type character varying
Something is wrong with article_id. I put it as string here. However when I manually try this query in PostgreSQL everything works(((