Configuring C3P0 data Sources in spring

Source: Internet
Author: User
Tags aop xmlns

1:applicationcontext.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:context= "Http://www.springframework.org/schema/context"
Xmlns:util= "Http://www.springframework.org/schema/util"
xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
xmlns:p= "http://www.springframework.org/schema/p"
Xmlns:jdbc= "Http://www.springframework.org/schema/jdbc"
Xsi:schemalocation= "Http://www.springframework.org/schema/jdbc
Http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop.xsd
Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
Http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd ">

<!--importing resource files--
<context:property-placeholder location= "Classpath:db.properties"/>
<!--configuring C3P0 data Sources--
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" >
<property name= "User" ><value>root</value></property>
<property name= "Password" ><value>123456</value></property>
<property name= "Jdbcurl" ><value>jdbc:mysql://localHost/mydatabase</value></property>
<property name= "Driverclass" ><value>com.mysql.jdbc.Driver</value></property>
<property name= "Initialpoolsize" ><value>5</value></property>
<property name= "Minpoolsize" ><value>5</value></property>
<property name= "Maxpoolsize" ><value>10</value></property>
</bean>
</beans>


2:db.properties

Username=root
password=123456
Jdbcurl=jdbc:mysql://localhost/mydatabase
Driverclass=com.mysql.jdbc.driver
Minpoolsize=5
Initialpoolsize=5
Maxpoolsize=15

3:junit

Package com.spring.jdbc;


Import static org.junit.assert.*;


Import java.sql.SQLException;


Import Javax.sql.DataSource;


Import org.junit.Test;
import org.springframework.context.ApplicationContext;
Import Org.springframework.context.support.ClassPathXmlApplicationContext;


public class Jdbctest {
  private applicationcontext ctx=null;
  {
 ctx=new CLASSP Athxmlapplicationcontext ("Applicationcontext.xml");
 }
@Test
public void Test () throws SQLException {
DataSource datasource=ctx.getbean (datasource.class);
System.out.println (Datasource.getconnection ());
}
}

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.