<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<!-- 最多可以创建多少个statement -->
<!-- 最多可以创建多少个statement -->
<property name="maxStatements">50</property>
<!-- 最多有多少个连接 -->
<property name="maxPoolSize">4</property>
<property name="initialPoolSize">2</property>
<property name="acquireIncrement">2</property>
<property name="minPoolSize">2</property>
<!-- 连接的超时间 -->
<property name="checkoutTimeout">3000</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql:///abc
</property>
<property name="user">root</property>
<property name="password">1234</property>
</default-config> <!-- 配置其他的连接,用户的其他配置可以有多个 --> <named-config name="jtedu"> <property name="maxStatements">50</property>
<!-- 最多有多少个连接 -->
<property name="maxPoolSize">4</property>
<property name="initialPoolSize">2</property>
<property name="acquireIncrement">2</property>
<property name="minPoolSize">2</property>
<!-- 连接的超时间 -->
<property name="checkoutTimeout">3000</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql:///abc
</property>
<property name="user">root</property>
<property name="password">1234</property>
</named-config>
</c3p0-config>
package c3p0连接池;

import java.sql.Connection;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class c3p0Utiles {

//    public static void main(String[] args) {
// System.err.println(c3p0Utiles.getCon());
//
// } private static DataSource ds;
static {
//默认配置
ds = new ComboPooledDataSource();
//指定配置
//ds=new ComboPooledDataSource("jteud"); } public static DataSource getDs() { return ds;
} public static Connection getCon() {
Connection con = null;
try {
con = ds.getConnection();
} catch (Exception e) { e.printStackTrace();
} return con;
} }

c3p0连接数据库的更多相关文章

  1. c3p0连接数据库的3种方式

    c3p0连接数据库的3种方式,这里以mysql为例 1. 直接用set方法设置参数, 基本方法 ComboPooledDataSource dataSource = new ComboPooledDa ...

  2. c3p0 连接数据库失败的问题

    报错:java.sql.SQLException: No suitable driver 显然,这里c3p0由于没有找到对应的配置文件(c3p0-config.xml或者c3p0.properties ...

  3. JAVA通过C3P0连接数据库

    配置文件: <?xml version="1.0" encoding="UTF-8"?> <c3p0-config>    <na ...

  4. Spring与C3p0连接数据库对事务操作

    maven包: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncodin ...

  5. dea创建Maven工程用c3p0连接数据库报错java.sql.SQLException: Connections could not be acquired from the underlying

    idea   java.sql.SQLException: Connections could not be acquired from the underlying database! 转载自:ht ...

  6. 数据库连接池技术,c3p0

    百度 谷歌  http://commons.apache.org/   可以找到DBCP   ,  这里选择使用C3P0,百度一下.https://www.mchange.com/projects/c ...

  7. Spring连接数据库

    public class Book { private int bookid; private String bookname; private String bookauthor; private ...

  8. JavaWeb_(Hibernate框架)Hibernate与c3p0与Dbutils的区别

    JavaWeb_(Hibernate框架)使用Hibernate开发用户注册功能 传送门 JavaWeb_(Hibernate框架)使用c3p0与Dbutils开发用户注册功能 传送门 Hiberna ...

  9. jquery+ajax+struts2

    AJAX 是与服务器交换数据的艺术,它在不重载全部页面的情况下,实现了对部分网页的更新.编写常规的 AJAX 代码并不容易,因为不同的浏览器对 AJAX 的实现并不相同.这意味着您必须编写额外的代码对 ...

随机推荐

  1. SQL获取选中时间的交集

    如上图:t1,t2代表要选择的时间段,t3,t4代表系统时间. 那么如果要获取选中时间段所有的交集为: 条件1 and ((t3>t1 and t1>t2) or (t3<t2 an ...

  2. VC中遍历进程并获取进程信息

    代码如下: /***************************************************/ /* 函数: 遍历进程信息 /* 参数:进程名称 例如: aaa.exe /* ...

  3. css实现超连接按钮形式显示

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  4. hdu4006 优先队列

    A - 签到 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65768KB     64bit I ...

  5. poj1159 dp(滚动数组优化)

    H - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:65536KB     ...

  6. hdu 2438

    Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...

  7. angular.js学习

    1.第一个小例子 <!DOCTYPE html> <html> <body> <div ng-app=""> <p>在输 ...

  8. macbook安装mysql

    一.官网下载dmg文件 二.双击安装dmg文件,一路next: 三.

  9. HDU 5417 Victor and Machine

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5417 Problem Description Victor has a machine. When t ...

  10. keepalived+httpd 做web服务的高可用

    场景: 环境中有两台httpd服务器,一台做主,一台做备用:平时只用主向外提供http服务:当主宕机后,keepalived把vip绑定到备机上去,这样就由备机提供http服务了. **keepalv ...