zoukankan      html  css  js  c++  java
  • spring配置c3p0连接池

    笔记做一下:

    spring中配置c3p0连接池:

    //倒入jar包:
    c3p0-0.9.2.1.jar(c3p0连接池jar包)
    mchange-commons-java-0.2.3.4(spring和c3p0依赖的jar包)

    以上jar包导入到项目下WEB-INF下的lib中

    方法一:代码实现

    1 ComboPooledDataSource dataSource = new ComboPooledDataSource();
    2 data.setDriverClass("com.mysql.jdbc.Driver");
    3 data.setJdbcUrl("jdbc:mysql:///books");    //端口号默认为3306
    4 data.setUser("root");
    5 data.setPassword("root");

    这样就设置了c3p0的连接信息


    方法二:在配置文件中进行配置(常用)

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4 xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="
     5 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
     6 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- bean definitions here -->
     7 
     8 
     9 <!-- 配置c3p0连接池 -->
    10 
    11 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    12 
    13   <!-- 注入相应的属性 -->
    14   <property name="DriverClass" value="com.mchange.v2.c3p0.ComboPooledDataSource"></property>
    15   <property name="jdbcUrl" value="jdbc:mysql:///books"></property>
    16   <property name="user" value="root"></property>
    17   <property name="password" value="root"></property>
    18 
    19 </bean>
    20 
    21 </beans>
  • 相关阅读:
    微信带参数二维码保存至本地
    合并图片添加水印并压缩文件提供下载
    C#压缩文件夹坑~
    JS中Float类型加减乘除 修复
    JQ 操作 radio、checkbox 、select
    jquery.uploadifive 解决上传限制图片或文件大小
    2017好好写博客咯
    LINQ to SQL Count/Sum/Min/Max/Avg Join
    LINQ to SQL:Where、Select/Distinct
    微信开发那点事(No.001)
  • 原文地址:https://www.cnblogs.com/caizhen/p/7862596.html
Copyright © 2011-2022 走看看