spring--three ways to configure data sources: Spring built-in, C3P0, DBCP

Source: Internet
Author: User

  

01.Spring built-in data source configuration
Class:drivermanagerdatasource
Fully qualified name: Org.springframework.jdbc.datasource.DriverManagerDataSource
No need to add any jars

DBCP data source configuration for 02.apache
Class:basicdatasource
Fully qualified name: Org.apache.commons.dbcp.BasicDataSource
Need to add: Com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar
Com.springsource.org.apache.commons.pool-1.5.3.jar

Data source configuration for 03.C3P0
Class:combopooleddatasource
Fully qualified name: Com.mchange.v2.c3p0.ComboPooledDataSource
Need to add: Com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar

Reference external data source configuration information settings: ${jdbc.*}
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name= "Driverclass" value= "${jdbc.driver}" ></property>
<property name= "Jdbcurl" value= "${jdbc.url}" ></property>
<property name= "user" value= "${jdbc.user}" ></property>
<property name= "Password" value= "${jdbc.password}" ></property>
</bean>

Jdbc.properties

1 jdbc.driver=oracle.jdbc.driver.OracleDriver2 jdbc.url=jdbc\:oracle\:thin\:@ Localhost\:1521\:orcl3 jdbc.user=zym4 jdbc.password=zymm
jdbc.properties

Write in two ways that refer to Jdbc.properties:
<!--01. Let Spring find jdbc.properties--
<bean class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name= "Location" value= "Classpath:jdbc.properties" ></property>
</bean>

<!--02. Let Spring find jdbc.properties--
<context:property-placeholder location= "Classpath:jdb.properties"/>

1<?xml version="1.0"encoding="UTF-8"?>2<beans xmlns="Http://www.springframework.org/schema/beans"3Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"4xmlns:aop="HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"5xmlns:tx="Http://www.springframework.org/schema/tx"6xsi:schemalocation="7http//Www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd8http//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOPhttp://www.springframework.org/schema/aop/spring-aop.xsd9http//Www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdTen         "> One<!-- on. Database connection settings spring built-in DB connection settings- A<bean id="DataSource" class="Org.springframework.jdbc.datasource.DriverManagerDataSource"> -          -<!--Drive Class-- the<property name="Driverclassname"Value="Oracle.jdbc.driver.OracleDriver"></property> -<!--URL address-- -<property name="URL"Value="Jdbc:oracle:thin: @localhost: 1521:orcl"></property> -<property name="username"Value="Zym"></property> +<property name="Password"Value="zymm"></property> -</bean> +      A      at      -<!-- Geneva. DBCP Configuration Data Source- -<bean id="DataSource" class="Org.apache.commons.dbcp.BasicDataSource"> -<property name="Driverclassname"Value="Oracle.jdbc.driver.OracleDriver"></property> -<property name="URL"Value="Jdbc:oracle:thin: @localhost: 1521:orcl"></property> -<property name="username"Value="Zym"></property> in<property name="Password"Value="zymm"></property> -</bean> to      +<!--Geneva. C3P0 Configuration Data Source- -<bean id="DataSource" class="Com.mchange.v2.c3p0.ComboPooledDataSource"> the<property name="Driverclass"Value="${jdbc.driver}"></property> *<property name="Jdbcurl"Value="${jdbc.url}"></property> $<property name="User"Value="${jdbc.user}"></property>Panax Notoginseng<property name="Password"Value="${jdbc.password}"></property> -</bean> the      +      A      the<bean id="myjdbctemplate" class="org.springframework.jdbc.core.JdbcTemplate"> +<property name="DataSource" ref="DataSource"></property> -</bean> $<bean id="Empdao" class="Zym.jdbctemplate.dao.impl.EmpDaoImpl"> $<property name="JdbcTemplate" ref="myjdbctemplate"></property> -</bean> -      the<bean id="Empservice" class="Zym.jdbctemplate.service.impl.IEmpServiceImpl"> -<property name="DAO" ref="Empdao"></property>Wuyi</bean> the          -<!--let spring look for jdbc.properties-- Wu<beanclass="Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> -<property name=" Location"Value="classpath:jdbc.properties"></property> About</bean> $</beans>
three ways of configuring code

Three ways to configure code instance with Jar Package version: Link: http://pan.baidu.com/s/1c2l2WwC Password: d2mu

spring--three ways to configure data sources: Spring built-in, C3P0, DBCP

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.