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 ?
By default, most JDBC drivers use a fetch size of 10. , so if you are reading 1000 objects, increasing the fetch size to 256 can significantly reduce the time required to fetch the query's results.
Spring - NamedParameterJdbcTemplate Example Functionally, there's no difference between Spring's JdbcTemplate and it's variant, NamedParameterJdbcTemplate except for : NamedParameterJdbcTemplate provides a better approach for assigning sql dynamic parameters instead of using multiple '?' in the statement.
NamedParameterJdbcTemplate - wraps a JdbcTemplate to provide more convenient usage with named parameters instead of the traditional JDBC "?" place holders. This provides better documentation and ease of use when you have multiple parameters for an SQL statement. Works with JDK 1.4 and up.
jdbc. core. NamedParameterJdbcTemplate class is a template class with a basic set of JDBC operations, allowing the use of named parameters rather than traditional '?' placeholders.
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-
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