How can I execute the following SQL in a scalable way using JdbcTemplate running on mySQL. In this case, scalable means:
- Only one SQL statement is executed on the server
- it works for any number of rows.
Here's the statement:
INSERT INTO myTable (foo, bar) VALUES ("asdf", "asdf"), ("qwer", "qwer")
Assume that I have a list of POJO's with foo
and bar
fields. I realize that I could just iterate over the list and execute:
jdbcTemplate.update("INSERT INTO myTable(foo, bar) VALUES (?, ?)", paramMap)
but that doesn't doesn't accomplish the first criterion.
I believe I could also execute:
jdbcTemplate.batchUpdate("INSERT INTO myTable(foo, bar) VALUES (?, ?)", paramMapArray)
but from what I can tell, that will just compile the SQL once and execute it multiple times, failing the first criterion again.
The final possibility, which seems to pass both criteria, would be to simply build the SQL myself with a StringBuffer
, but I'd like to avoid that.