Posts Tagged ‘jdbc’

Spring Framework and the JdbcDaoSupport

Tuesday, July 10th, 2007

Spring offers a handy class to implement DAO support with JDBC. Its called JdbcDaoSupport and offers methods to access the DataSource in your application context configuration. Here´s an example from the book “Java Development with the Spring Framework“:

public class TestJdbcDao extends JdbcDaoSupport {
    private final static String QUERY = "select count(*) from dual";
    public int getTestAccount(){
        return getJdbcTemplate().queryForInt(QUERY);
    }
}

And the corresponding dataAccessContext.xml

<bean id="dao" class="TestJdbcDao">

<property name="dataSource">

<ref local="dataSource"/>

</property>

</bean>