deepak
deepak

Reputation: 339

NamedParameterJdbcTemplate batch size

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.

Upvotes: 5

Views: 2921

Answers (1)

Grade
Grade

Reputation: 574

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.

Upvotes: 1

Related Questions