spring获取数据库连接对象

来源:互联网 发布:淘宝实名认证手机 编辑:程序博客网 时间:2024/05/22 03:07

12020171030

120201710301、导入数据库相关jar包:spring-jdbc-4.3.6.RELEASE.jar、spring-tx-4.3.6.RELEASE.jar2、在src下创建资源文件db.properties3、配置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#MySQLjdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/book?useUnicode=true&characterEncoding=utf8&useSSL=truejdbc.username=rootjdbc.password=123456#oracle#jdbc.driverClassName=oracle.jdbc.driver.OracleDriver#jdbc.url=jdbc:oracle:thin:@localhost:1521:ORCL#jdbc.username=root#jdbc.password=root

原创粉丝点击