12020171030
12020171030
1、导入数据库相关jar包:spring-jdbc-4.3.6.RELEASE.jar、spring-tx-4.3.6.RELEASE.jar
2、在src下创建资源文件db.properties
3、配置beans.xml文件
4、测试文件,获取数据连接对象
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
//获取数据源
DataSource ds = (DataSource) ctx.getBean("simple_ds");
//获取数据连接对象
Connection conn = ds.getConnection();
#Let's talk about this file in src catalog
#MySQL
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/book?useUnicode=true&characterEncoding=utf8&useSSL=true
jdbc.username=root
jdbc.password=123456
#oracle
#jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@localhost:1521:ORCL
#jdbc.username=root
#jdbc.password=root