Lot Size NamedParameterJdbcTemplate

Is there a way to set the batch size for the Spring object's NamedParameterJdbcTemplate?

I ran into some OutOfMemory problems in my project, but I was able to solve it by calling NamedParameterJdbcTemplate in a loop of smaller fragments. But this required a few additional efforts, such as determining the size of a piece, breaking a large list into smaller sublists, etc.

I was wondering if NamedParameterJdbcTemplate has such a direct way, I can specify the batch size for it. I don't see anything in the API documentation. But they have something in the JDBCTemplate. Now, if I need to switch to JDBCTemplate, I will have to redo the code: (

Please offer.

+4
source share
1 answer

You cannot do this directly with NamedParameterJdbcTemplate , but you can call #getJdbcOperations through the implemented NamedParameterJdbcOperations interface. Its return type JdbcOperations is currently only implemented by the classic JdbcTemplate and has the #batchUpdate method you need. However, you cannot use named parameters in this scenario.

See a typical usage example from Spring docs.

0
source

Source: https://habr.com/ru/post/1501002/


All Articles