spring 框架jdbc连接数据库
2017-01-17 09:58
459 查看
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框架连接并操作数据库
- 使用Spring JDBC框架连接并操作数据库
- Hibernate、SpringJDBC中在注解模式下获取数据库连接
- Spring Boot JDBC 连接数据库
- 如何使用三层框架开发 JDBC 连接 Mysql 数据库
- 原生无框架JDBC实现数据库连接和Servlet页面的基本操作
- [Spring3.x] 第 11 章 使用 Spring JDBC 访问数据库 & 第 12 章 整合其他 ORM 框架
- SpringBoot实践之---JDBC连接数据库
- Spring的连接数据库以及JDBC模板(实例讲解)
- Spring Boot JDBC 连接数据库
- 【Spring】整合JDBC连接数据库
- Spring数据库数据源JDBC连接池连接MySQL的超时问题
- spring通过jdbc连接数据库
- Spring中使用JDBC连接数据库的配置
- Spring和数据库连接 --- 征服数据库jdbc
- Spring与JDBC连接实现对数据库的增删改查
- [Spring3.x] 第 11 章 使用 Spring JDBC 访问数据库 & 第 12 章 整合其他 ORM 框架
- java三大框架spring的JdbcTemplate连接数据库(C3P0)
- spring-jdbc模板连接数据库(增删改查)
- Spring中使用纯JDBC连接数据库的配置