• spring 框架jdbc连接数据库


    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();
            }
            
            
            
        }
        
    
        
        
    }
  • 相关阅读:
    House of hello恶搞包之真假辨别
    Window phone用手机来控制电脑的多媒体播放
    《你是我的小羊驼》游戏ios源码
    打地鼠游戏ios源码
    Android系统的架构
    魔兽塔防游戏android源码
    抢滩登陆游戏android源码
    Java学生管理系统项目案例
    UITextView如何关闭键盘
    view上添加点手势 button无法响应点击事件
  • 原文地址:https://www.cnblogs.com/lantu1989/p/6291877.html
Copyright © 2020-2023  润新知