September 3, 2017 different ways to connect databases in spring and MyBatis

Source: Internet
Author: User
Tags connection pooling

Connecting the database with the methods used in spring and MyBatis can not be the same, mybaits can not write the database configuration file

Spring's Connection method

<!--read the contents of the property file (. properties)--

<!--location: Specifies the position and file name of the property file to be read.
Note: classpath: Indicates that the contents of the property file are read by the path according to the classpath.
and store the content on the Properties object-

Log in data file for database
File name db.properties
#db connection Parametersdriver=oracle.jdbc.driver.OracleDriverurl=jdbc:oracle:thin:@ 176.217.20.254:1521: Tarenauser=abc1234pwd=abc1234#datasource parametersinitsize=1 maxsize=3

Write in the XML configuration file:

<util:properties id="DB"location="classpath:db.properties"/> <!--Configuring connection pooling--<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 Method of Connection

MyBatis directly in the XML write

1<environmentsdefault= "Environment" >2<environment id= "Environment" >3<transactionmanager type= "JDBC"/>//Select to use the JDBC interface4<datasource type= "Pooled" >5<property name= "Driver" value= "Oracle.jdbc.driver.OracleDriver"/>6<property name= "url"7Value= "Jdbc:oracle:thin:@176.217.20.254:1521:tarena"/>8<property name= "username" value= "abc1234"/>9<property name= "Password" value= "abc1234"/>Ten</dataSource> One</environment> A</environments>

September 3, 2017 different ways to connect databases in spring and MyBatis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.