user641887
user641887

Reputation: 1586

fetch size for NamedParameterJdbctemplate?

I am working on a problem which involves me to write a query to fetch few thousands of records from the database. The query which I would be using will include 2 IN clauses in the WHERE condition.

As per my knowledge which might be limited, please feel to correct me, for this use case I cannot use jdbctemplate. I would have to move towards NamedParameterJdbcTemplate since NamedParameterJdbcTemplate gives us the flexibility to use IN clause.

Now my questions which I am looking answers for are as follows.

Q.> NamedParameterJdbcTemplate does not have a setFetchSize method. Is there a way to set the fetch size for NamedParameterJdbcTemplate ?

Q> Does anyone has any idea about the default fetch size for the NamedParameterJdbcTemplate ? for JdbcTemplate it is set to 10. I know. What about NamedParameterJdbcTemplate ?

Q> even if i use NamedParameterJdbcTemplate my problem would not be resolved, since if we assume that the fetch size of NamedParameterJdbcTemplate would also be 10, fetching few thousand records would still take a lot of my application time.

Can anyone suggest a solution or guide me in the right direction ?

Upvotes: 5

Views: 7870

Answers (1)

Thomas Risberg
Thomas Risberg

Reputation: 976

The NamedParameterJdbcTemplate delegates to a plain JdbcTemplate for all JDBC work. So, you can create your NamedParameterJdbcTemplate passing in a customized JdbcTemplate in the constructor. If you customize the fetchSize on the JdbcTemplate you pass in, then that is what the NamedParameterJdbcTemplate will use as well. See - https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.html#NamedParameterJdbcTemplate-org.springframework.jdbc.core.JdbcOperations-

Upvotes: 9

Related Questions