2017年9月3日 Spring及Mybatis中连接数据库的不同方式
连接数据库用spring和mybatis中使用的方法可以不同,mybaits可以不用写数据库的配置文件
Spring的连接方法
<!-- 读取属性文件(.properties)的内容 -->
<!-- location:指定要读取的属性文件的位置及文件名.
注: classpath:表示依据类路径去查找 容器依据路径读取属性文件的内容,
并且将这些内容存放到Properties对象上 -->
//数据库的登入数据文件
//文件名db.properties
#db connection parameters
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@176.217.20.254:1521:tarena
user=abc1234
pwd=abc1234
#datasource parameters
initsize=1
maxsize=3
在xml配置文件中写入:
<util:properties id="db" location="classpath:db.properties" />
<!-- 配置连接池 -->
<bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="#{db.driver}" />
<property name="url" value="#{db.url}" />
<property name="username" value="#{db.user}" />
<property name="password" value="#{db.pwd}" />
<property name="initialSize" value="#{db.initsize}" />
</bean>
mybatis的连接方法
mybatis中直接在xml写入即可
<environments default="environment">
<environment id="environment">
<transactionManager type="JDBC" /> //选择使用JDBC接口
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="url"
value="jdbc:oracle:thin:@176.217.20.254:1521:tarena" />
<property name="username" value="abc1234" />
<property name="password" value="abc1234" />
</dataSource>
</environment>
</environments>
2017年9月3日 Spring及Mybatis中连接数据库的不同方式的更多相关文章
- 免费公共DNS服务器IP地址大全(2017年6月24日)
收集全球各个常用公共DNS服务器 IP地址,欢迎各位朋友评论补充! 国内常用公共DNS 114 DNS: (114.114.114.114: 114.114.115.115) 114DNS安全版 ...
- 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...
- [转载]Ubuntu17.04(Zesty Zapus)路线图发布:2017年4月13日发布
Canonical今天公布了Ubuntu 17.04(Zesty Zapus)操作系统的发布路线图,该版本于今年10月24日上线启动,toolchain已经上传且首个daily ISO镜像已经生成.面 ...
- 2017年1月5日 星期四 --出埃及记 Exodus 21:31
2017年1月5日 星期四 --出埃及记 Exodus 21:31 This law also applies if the bull gores a son or daughter.牛无论触了人的儿 ...
- 2017年1月4日 星期三 --出埃及记 Exodus 21:30
2017年1月4日 星期三 --出埃及记 Exodus 21:30 However, if payment is demanded of him, he may redeem his life by ...
- 2017年1月3日 星期二 --出埃及记 Exodus 21:29
2017年1月3日 星期二 --出埃及记 Exodus 21:29 If, however, the bull has had the habit of goring and the owner ha ...
- 2017年1月2日 星期一 --出埃及记 Exodus 21:28
2017年1月2日 星期一 --出埃及记 Exodus 21:28 "If a bull gores a man or a woman to death, the bull must be ...
- 2017年1月1日 星期日 --出埃及记 Exodus 21:27
2017年1月1日 星期日 --出埃及记 Exodus 21:27 And if he knocks out the tooth of a manservant or maidservant, he ...
- 2017年1月8日 星期日 --出埃及记 Exodus 21:34
2017年1月8日 星期日 --出埃及记 Exodus 21:34 the owner of the pit must pay for the loss; he must pay its owner, ...
随机推荐
- JDK+Tomcat+Zookeeper+DubboAdmin安装教程
JDK+Tomcat+Zookeeper+DubboAdmin安装教程 1. 安装内容: JDK 1.8.131 Tomcat 7.0.77 Zookeeper 3.4.9 Dubbo admin 2 ...
- 【grunt】grunt 基础学习
1. 干啥的呢? 项目打包管理,用处有 1)可用于压缩合并前端文件,包括css/js , 2)可用于管理发布文件与开发文件,3)可用于自动编译less 文件 2. 常用的东西有哪些呢? 常用的插件有 ...
- PHP中使用单双引号的区别
1,双引号可以解析变量,单引号不可以解析: 2,双引号解析转义字符,单引号不解析转义,但是可以解析 \' 和 \\ ; 3,单双引号不能自己套自己,要嵌套使用,避免混乱: 4,单引号效率更高,能使 ...
- hadoop入门,跑出第一个WordCount
1.环境准备 下载:http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.7.2/hadoop-2.7.2.tar.gz 解压:解压后,修改et ...
- codeforces 475D. CGCDSSQ
D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes Given a sequence of int ...
- RSA简介(二)——模幂算法
RSA最终加密.解密都要用到模乘的幂运算,简称模幂运算. 回忆一下RSA,从明文A到B B=Ae1%N 对B解密,就是 A=Be2%N 其中,一般来说,加密公钥中的e1一般会比较小,取65537居多, ...
- 5.npm scripts 使用指南
简单介绍 scripts里面的 "start": "node app" npm run start 相当于 node app { "name" ...
- Spring初始化ApplicationContext线程托管实际运用架构构思
今天我分享一个技术点,利用Spring初始化+线程接管进行程序启动后保持会话状态. 先来一段@test单元测试注解,后台开发的很熟悉,这是测试局部代码用的: @RunWith(SpringJUnit4 ...
- 将SpringMVC中的HttpMessageConverter替换为Gson
读者们看到这个标题也许会感到奇怪,SpringMVC中默认的HttpMessageConverter不是Jackson吗,但是我在使用的过程中发现Jackson并不好用,如果有一些复杂的嵌套类型,当然 ...
- akoj-1059-Picture
Description 给你一个矩形的宽度和高度,要求按sample output样例输出此矩形. Input 输入包含多组数据,每一组包含两个数N和M( 0 < N ,M , < 75 ...