spring2.5学习笔记之三:spring对JDBC的支持

在DAO类中,我们继承Spring的DAO,代码如下:
jdbcDaoSupport 写道
import java.util.List;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.spring.manageri.UserDaoManager;
public class Test extends JdbcDaoSupport implements UserDaoManager {

@Override
public List getUserLists() {
String sql="select * from table where ...";
List list=this. getJdbcTemplate ().queryForList(sql);
return list;
}

@Override
public void showMessage() {
// TODO Auto-ge
 
 nerated method stub

}
}
 

然后,我们在配置文件里面,把每个JdbcTemplate注入到每个DAO中。

jdbcTemplace注入DAO 写道
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" p:driverClass="${jdbc.driverClass}"
p:jdbcUrl="${jdbc.jdbcUrl}" p:user="${jdbc.user}"
p:password="${jdbc.password}">
<property name="initialPoolSize"
value="5" />
<property name="maxPoolSize" value="10" />
</bean>

<bean id=" jdbcTemplate "
class="org.springframework.jdbc.core. JdbcTemplate ">

<property name="dataSource" ref="dataSource"</property>
</bean>

<bean id="dao" abstract =" true ">
< property name=" jdbcTemplate " ref=" jdbcTemplate "/>
</bean>

<bean id=" UserDaoManagerImpl " paraent =" dao " class="com.spring.impl.UserDaoManagerImpl"/>

 

 

你可能感兴趣的:(DAO,spring,sql,bean,jdbc)