首页 > 数据库技术 > 详细

spring 框架jdbc连接数据库

时间:2017-01-17 10:24:45      阅读:317      评论:0      收藏:0      [点我收藏+]
user=LF
password=LF
url=jdbc:oracle:thin:@localhost:1521:orcl
driver=oracle.jdbc.driver.OracleDriver
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">


    <context:property-placeholder location="classpath:jdbc.properties"/>
    <bean id="connection" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="username" value="${user}"></property>
        <property name="password" value="${password}"></property>
        <property name="driverClassName" value="${driver}"></property>
        <property name="url" value="${url}"></property>
    </bean>
    
</beans>
public class Utils_jdbc {
    
    public static void main(String[] args) {
        
        ApplicationContext ctc = new ClassPathXmlApplicationContext("applicationContext.xml");

        
        DriverManagerDataSource dSource = (DriverManagerDataSource) ctc.getBean("connection");
        
        try {
            
            System.out.println(dSource.getConnection());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        
        
    }
    

    
    
}

 

spring 框架jdbc连接数据库

原文:http://www.cnblogs.com/lantu1989/p/6291877.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!