Simple Spring JDBC Template

David Winterfeldt

2008


A simple example using SimpleJdbcTemplate.

1. Spring Configuration

The Spring JDBC Template just needs a DataSource. This DataSource automatically initializes an HSQL DB with the schema.sql script.

                
<bean id="dataSource"
      class="org.springbyexample.jdbc.datasource.HsqldbInitializingDriverManagerDataSource">
    <property name="sqlScriptProcessor">
        <bean class="org.springbyexample.jdbc.core.SqlScriptProcessor">
            <property name="sqlScripts">
                <list>
                    <value>classpath:/schema.sql</value>
                </list>
            </property>
        </bean>
    </property>
</bean>