I want to execute multiple, separate SQL statements like in the JDBC cookbook:
Statement stmt = con.createStatement();
stmt.addBatch(
"update registration set balance=balance-5.00
where theuser="+theuser);
stmt.addBatch(
"insert into auctionitems(
description, startprice)
values("+description+","+startprice+")");
Must I use the Statement object directly? I’m looking for some spring JDBCTemplate service that provides the same functionality.
Extra points: Even better would be a service that takes a text with multiple SQL statements separated with ; and executes them all.
Thanks, Ido
JdbcTemplatehas twobatchUpdatemethods that provide this functionality (javadoc). Which one you use depends on how much control you need. If you need full control, you can use theexecute(StatementCallback)or evenexecute(ConnectionCallback)methods.