Spring JDBC template batchUpdate: multiple update statements
Posted by: Hugo Ribeiro
Date: July 23, 2024 10:02AM

Hey, hope you are doing great.

I have the following question/doubt: I am using spring jdbctemplate batchUpdate method passing in a prepared statement and a batch of params. What it then does is to grab that update statement, iterate every entry on the batch and create multiple update statemens separated by ";".

e.g.
update abc set col1 = ? where id = ?
batch -> [[val1, id1], [val2, id2], [val3, id3], [val4, id4]]

the following statement is created and executed:
update abc set col1=val1 where id=id1;update abc set col1=val2 where id=id2;update abc set col1=val3 where id=id3;update abc set col1=val4 where id=id4;

I am facing the following exception:
Caused by: java.sql.SQLException: syntax error at position 6 near 'pdate'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130) ~[mysql-connector-j-8.1.0.jar:8.1.0]

but if I grab the statement and try to run it e.g. on dbeaver it works.

Can you tell me what am I doing wrong here?

Thanks in advance.

Options: ReplyQuote




Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.