Is there a way to set the batch size for Spring's NamedParameterJdbcTemplate object?
I ran into some OutOfMemory issues in my project but I was able to resolve it by calling NamedParameterJdbcTemplate in a loop of smaller chunks. But this required some extra effort like deciding the chunk size, breaking a big List into smaller sublists etc.
I was wondering if NamedParameterJdbcTemplate has any such direct way by I can specify the batch size for it. I do not see anything though in the API documentation. But they have something in JDBCTemplate. Now if I have to switch to JDBCTemplate I will have to redo my code :(
Please suggest.
You can't do this directly with NamedParameterJdbcTemplate
, but you can call #getJdbcOperations method via implemented NamedParameterJdbcOperations
interface. Its return type, JdbcOperations
, is currently implemented only by classic JdbcTemplate
and has #batchUpdate method that you need. However, you can't use named parameters in this scenario.
See the example of typical usage from Spring docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With