码迷,mamicode.com
首页 > 数据库 > 详细

Spring与JDBC整合

时间:2015-11-05 22:27:52      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

aspectjrt.jar
aspectjweaver.jar
cglib-nodep-2.1_3.jar
commons-dbcp.jar
commons-logging.jar
commons-pool.jar
mysql-connector-java-5.1.10-bin.jar
spring.jar

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
      <!-- 
          用于配置解析文件
          引入prperties配置文件
          
       -->
      <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>classpath:jdbc.properties</value>
        </property>
    </bean>
    
      <bean id="dataSource" destroy-method="close"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>
       
    <bean id="personDao3" class="com.spring.jdbc.dao.PersonDao">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
    </bean>


</beans>

 

package com.spring.jdbc.dao;

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

public class PersonDao extends JdbcDaoSupport{
    public void savePerson(String sql){
        this.getJdbcTemplate().execute(sql);
    }
}

 

Spring与JDBC整合

标签:

原文地址:http://www.cnblogs.com/thinkpad/p/4940823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!