连接数据库用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中连接数据库的不同方式的更多相关文章

  1. 免费公共DNS服务器IP地址大全(2017年6月24日)

    收集全球各个常用公共DNS服务器 IP地址,欢迎各位朋友评论补充! 国内常用公共DNS 114 DNS: (114.114.114.114:    114.114.115.115) 114DNS安全版 ...

  2. 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS

    一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...

  3. [转载]Ubuntu17.04(Zesty Zapus)路线图发布:2017年4月13日发布

    Canonical今天公布了Ubuntu 17.04(Zesty Zapus)操作系统的发布路线图,该版本于今年10月24日上线启动,toolchain已经上传且首个daily ISO镜像已经生成.面 ...

  4. 2017年1月5日 星期四 --出埃及记 Exodus 21:31

    2017年1月5日 星期四 --出埃及记 Exodus 21:31 This law also applies if the bull gores a son or daughter.牛无论触了人的儿 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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, ...

随机推荐

  1. Golang 基于libpcap/winpcap的底层网络编程——gopacket安装

    Go简介 Go是一种编译型语言,它结合了解释型语言的游刃有余,动态类型语言的开发效率,以及静态类型的安全性. 语法类似C/C++,但是又带有一点python的味道 其中个人认为最出色的特点就是他的包管 ...

  2. SpringMVC源码情操陶冶-FreeMarker之web配置

    前言:本文不讲解FreeMarkerView视图的相关配置,其配置基本由FreeMarkerViewResolver实现,具体可参考>>>SpringMVC源码情操陶冶-ViewRe ...

  3. PHP删除文件夹及其文件

    <?php function deletedir($path){ $openpath = opendir($path); while ($f = readdir($openpath)){ $fi ...

  4. 安装完ubuntu16.4.0之后要做的一些优化

    1.删除libreoffice libreoffice虽然是开源的,但是Java写出来的office执行效率实在不敢恭维,装完系统后果断删掉 sudo apt-get remove libreoffi ...

  5. robot framework 怎么点击文本总结

    点击文本有一下几种方式 1.

  6. 奇怪的道路[JXOI2012]

    题目描述 小宇从历史书上了解到一个古老的文明.这个文明在各个方面高度发达,交通方面也不例外.考古学家已经知道,这个文明在全盛时期有n座城市,编号为1..n.m条道路连接在这些城市之间,每条道路将两个城 ...

  7. 求m区间内的最小值

    洛谷P1440 求m区间内的最小值 ............................................................................... 以上 ...

  8. 6,EasyNetQ-基于Topic的路由

    RabbitMQ具有非常酷的功能,基于主题的路由,允许订阅者基于多个标准过滤消息. 主题是与邮件一起发布的点分隔的单词列表. 例子是"stock.usd.nyse"或"b ...

  9. nodejs 文件读取一行

    作者QQ:1095737364    QQ群:123300273     欢迎加入!   废话没有,直接上代码: app.get('/company', function (req, res, nex ...

  10. JavaScript中的尾调用优化

    文章来源自:http://www.zhufengpeixun.com/qianduanjishuziliao/javaScriptzhuanti/2017-08-08/768.html JavaScr ...