PDA

View Full Version : SimpleJdbcTemplate equivalent for JdbcTemplate.setFetchSize



rellman_netflix
Feb 26th, 2008, 05:24 PM
I have a query where I am expecting to get a large number of results. When using JdbcTemplate, I would set the fetch size to help optimize. In converting over to SimpleJdbcTemplate, I can't find an equivalent method.

The SimpleJdbcDaoSupport class extends the JdbcDaoSupport class, but I was surprised that the Template classes did not have a similar relationship. I could get the JdbcTemplate from the DaoSupport, but then I have to box up the args and lose the advantages of Java 5.

Does anyone know of another method or something I may have missed.

Thanks,

--Rob Ellman

satkinson_netflix
Feb 27th, 2008, 11:15 PM
Rob,

Could you use a connection callback to set the fetch size?

wpoitras
Feb 28th, 2008, 08:36 AM
The SimpleJdbcTemplate is constructed from a JdbcTemplate. When you construct your DAO you should set a JdbcTemplate in your configuration rather than using a DataSource. Otherwise Spring will construct a JdbcTemplate for you. You can set the fetchSize on the JdbcTemplate you create.


<bean id="myTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="myDataSource"/>
<property name="fetchSize" value="${featch.size}"/>
</bean>

<bean id="myDao" class="com.mycompany.MyDaoImpl">
<property name="jdbcTemplate" ref="myTemplate"/>
</bean>

hotwater
Dec 10th, 2009, 01:39 PM
Thank you very much, Bill, great answer!

techluver
Dec 29th, 2009, 03:05 PM
Hello,

how can we set fetchsize at connection level when there is no set function
if i want to write below function?

public static void setFetchSize(final SimpleJdbcTemplate jdbcTemplate,
final int pFetchSize)
{

jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback()
{
public Object doInConnection(Connection connection)
throws SQLException, DataAccessException
{
//no setFetchSize() in connection.
//connection.createStatement().setFetchSize(pFetchSi ze);
return null;
}
});
}


Rob,

Could you use a connection callback to set the fetch size?