67,515
社区成员
发帖
与我相关
我的任务
分享
package com.xdl.DAO.imp;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;
import com.xdl.DAO.AccountNumDAO;
@Repository("AccountNumDAO_imp")
public class AccountNumDAO_imp extends JdbcDaoSupport implements AccountNumDAO {
@Autowired
@Qualifier(value="dataSource")
public AccountNumDAO_imp(DataSource dataSource) {
super.setDataSource(dataSource);
}
public int getAccountNum() {
return super.getJdbcTemplate().queryForObject("select count(*)from bank_account", Integer.class);
}
}
<context:component-scan base-package="com.xdl.DAO"></context:component-scan>
<util:properties id="db" location="classpath:com/xdl/util/dbcp.properties">
</util:properties>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="#{db.driverClassName}"></property>
<property name="url" value="#{db.url}"></property>
<property name="username" value="#{db.username}"></property>
<property name="password" value="#{db.password}"></property>
<property name="initialSize" value="#{db.initialSize}"></property>
</bean>
</beans>