c3p0使用
c3p0-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<named-config name="mvc">
<property name="user">root</property>
<property name="password">root</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF8</property>
<!-- ?useUnicode=true&characterEncoding=UTF8 -->
<property name="acquireIncrement">2</property>
<property name="initialPoolSize">5</property>
<property name="minPoolSize">5</property>
<property name="maxPoolSize">10</property>
<property name="maxStatements">20</property>
<property name="maxStatementsPerConnection">5</property>
</named-config>
</c3p0-config>
JdbcUtils
package Utils; import java.sql.Connection;
import java.sql.SQLException; import javax.sql.DataSource; import com.mchange.v2.c3p0.ComboPooledDataSource; public class JdbcUtil { public static void reaseConnection(Connection connection) {
try {
if(connection!=null){
connection.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static DataSource dataSource = null;
static{
dataSource = new ComboPooledDataSource("mvc");
} public static DataSource getDataSource(){
return dataSource;
} public static Connection getConnection(){
try {
return dataSource.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("连接失败");
}
return null; }
}
c3p0使用的更多相关文章
- c3p0连接数据库的3种方式
c3p0连接数据库的3种方式,这里以mysql为例 1. 直接用set方法设置参数, 基本方法 ComboPooledDataSource dataSource = new ComboPooledDa ...
- C3p0连接池配置
在Java开发中,使用JDBC操作数据库的四个步骤如下: ①加载数据库驱动程序(Class.forName("数据库驱动类");) ②连接数据库(Connection co ...
- .数据库连接池技术:DBCP和C3P0
数据库连接池技术:DBCP和C3P0 1.什么是数据库连接池 已知的方法是需要访问数据库的时候进行一次数据库的连接,对数据库操作完之后再释放这个连接,通常这样业务是缺点很明显的: 用户每次请求都需要向 ...
- C3P0连接池配置和实现详解
一.配置 <c3p0-config> <default-config> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数.Default: 3 --> ...
- 数据库连接池c3p0学习
这里只记录c3p0的数据源,不会涉及到其它方面和别的数据库连接池的对比 配置文件主要的实现方式有三种: 1.手写代码去加载一个配置文件 创建一个config.properties文件如下: drive ...
- c3p0 连接池
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destr ...
- oracle 和c3p0 数据库的Time_Wait 过多问题的一个解决方案。
项目是B/S模式,放在linux服务器上,tomcat和oracle11g在一台服务器上,tomcat读取数据库采用C3P0连接池,一直比较稳定,所以也没有去管.后来把tomcat放在一台win200 ...
- spring hibernate4 c3p0连接池配置
c3p0-0.9.1.2.jar,c3p0-oracle-thin-extras-0.9.1.2.jar,点此下载 <bean id="dataSource" class=& ...
- Spring配置c3p0数据源时出错报:java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector
今天在使用Spring配置c3p0数据源时,使用的数据库是mysql,服务器是tomcat,运行时报了一个 java.lang.NoClassDefFoundError: com/mchange/v2 ...
- c3p0数据库连接池的使用详解
首先,什么是c3p0?下面是百度百科的解释: C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展.目前使用它的开源项目有Hibernate,Sp ...
随机推荐
- shell中颜色的设置
linux启动后环境变量加载的顺序为:etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → [/etc/bashrc] 想 ...
- MongoDB的增、删、改、查操作(五)
按照我们关系型数据库的思想,一个服务器要想存放数据,首先要有数据库,表,字段,约束,当然了也少不了主键,外键,索引,关系等: 但是在MongoDB的世界里边,我们不用预先的去创建这些信息从而直接来使用 ...
- 通过docker-compose构建ghost博客(二)
上一篇通过yml文件构建 ghost博客,这次通过构建nginx服务,并添加反向代理来运行搭建的ghost博客. 目录结构 ghost.conf 就是 定义的nginx 加载的配置文件 server ...
- 使用swoole编写简单的echo服务器
server.php代码如下: <?php class EchoServer { protected $serv = null; public function __construct() { ...
- centos7下haproxy1.7的使用与配置
centos7下haproxy1.7的使用与配置 haproxy是一个使用C语言编写的自由及开放源代码软件,其提供高可用性.负载均衡,以及基于TCP和HTTP的应用程序代理. 一.haproxy下载 ...
- c# 24种设计模式
备忘录模式(Memento Pattern) 策略模式(Strategy Pattern) 抽象工厂模式(Abstract Factory Pattern) 代理模式(Proxy Pattern) 单 ...
- 24.Mysql高级安装和升级
24.Mysql高级安装和升级24.1 Linux/Unix平台下的安装 24.1.1 安装包比较Linux下的Mysql安装包分为RPM包.二进制包.源码包3种.RPM包优点是安装简单,适合初学者: ...
- 09. pt-fingerprint
vim pt-fingerprint.txt select name, password from user where id=5;select name, password from user wh ...
- python httplib2应用get post
import httplib2,time #装饰器方法,用于记录方法消耗时间 #推荐将print 改成log def timer(func): def _warpper(self,*argv) ...
- Spring 中的类加载机制 - ClassLoader
Spring 中的类加载机制 - ClassLoader Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) ClassLoa ...