首先在配置文件中定义
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>
file:${user.dir}/conf/config.properties
</value>
</list>
</property>
</bean>
配置文件
<bean id="xmsDataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc.OracleDriver" />
<property name="jdbcUrl" value="${xmsDataSource.url}" />
<property name="user" value="${xmsDataSource.username}" />
<property name="password" value="${xmsDataSource.password}" />
Spring 的JDBC对象
<bean id="appJdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="appDataSource" />
</property>
</bean>
在需要JDBC的对象上配置
<bean id="heartbeatUtil"
class="com.techown.smplatform.util.HeartbeatUtil">
<property name="xmsJdbcTemplate" ref="xmsJdbcTemplate"></property>
</bean>
使用update或者insert 等方法时候,需要指定 已经实现 PreparedStatementSetter 的对象。,如果是集合则需要实现BatchPreparedStatementSetter和getBatchSize()方法,getBatchSize()方法中传参是传入集合的大小,返回是int类型。实现query查询的时候,需要实现RowMapper 类。返回的就是一个集合。