c3p0

Java Database connection pool (BoneCP vs DBPool vs c3p0)

不打扰是莪最后的温柔 提交于 2019-11-29 23:04:14
For a Java app outside of a J2EE container, which connection pool library is the best? I heard c3p0 is getting outdated. Jakarta's common pool library is no longer under development Therefore I'm left with BoneCP and DBPool . From what I can tell both have limited activity. The main difference I can see is performance, which BoneCP seems to win out with. However the documentation is pretty weak. Which database pool library have you used in the real world and why? What was the good and bad? At work we have used BoneCP (as the replacement for c3p0) and as far as I know haven't had any issues (I

JDBC Connection pooling using C3P0

浪尽此生 提交于 2019-11-29 22:17:05
Following is my helper class to get DB connection: I've used the C3P0 connection pooling as described here . public class DBConnection { private static DataSource dataSource; private static final String DRIVER_NAME; private static final String URL; private static final String UNAME; private static final String PWD; static { final ResourceBundle config = ResourceBundle .getBundle("props.database"); DRIVER_NAME = config.getString("driverName"); URL = config.getString("url"); UNAME = config.getString("uname"); PWD = config.getString("pwd"); dataSource = setupDataSource(); } public static

Hibernate实战——映射数据库对象

北城余情 提交于 2019-11-29 21:54:30
一 配置文件 <?xml version="1.0" encoding="GBK"?> <!-- 指定Hibernate配置文件的DTD信息 --> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!-- hibernate-configuration是配置文件的根元素 --> <hibernate-configuration> <session-factory> <!-- 指定连接数据库所用的驱动 --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <!-- 指定连接数据库的url,其中hibernate是本应用连接的数据库名 --> <property name="connection.url">jdbc:mysql://localhost/hibernate</property> <!-- 指定连接数据库的用户名 --> <property name="connection.username">root<

数据库连接池

两盒软妹~` 提交于 2019-11-29 21:44:45
概念:存放数据库连接的集合,系统初始化时创建,        用户访问时从数据库获取连接,        访问结束将连接归还给集合 优点:节约时间,用户访问高效 实现:javax.sql包下的DataSource接口(由数据库厂商来实现)    C3P0:数据库连接池技术    Druid:数据库连接池实现技术,由阿里巴巴提供的 方法:获取连接:getConnection()    归还连接:close();若是通过数据库连接池获取的连接,使用close则为将连接归还连接池 C3P0使用步骤:     1、导入C3P0的jar包以及依赖包(c3p0-0.9.5.2.jar mchange-commons-java-0.2.12.jar)以及数据库驱动jar包     2、定义配置文件:名字必须为 c3p0.properties 或者 c3p0-config.xml,放在src目录下(自动加载)     3、创建核心对象:DataSource ds = new ComboPooledDataSource();     4、获取数据库连接:Connection conn = ds.getConnection(); Druid使用步骤     1、导入Druid的jar与数据库驱动包     2、定义并加载配置文件: properties 文件,可以防止任意位置,叫任意名字(手动加载

should i activate c3p0 statement pooling?

跟風遠走 提交于 2019-11-29 20:29:57
we are running java6/hibernate/c3p0/postgresql stack. Our JDBC Driver is 8.4-701.jdbc3 I have a few questions about Prepared Statements. I have read excellent document about Prepared Statements But i still have a question how to configure c3p0 with postgresql. At the moment we have c3p0.maxStatements = 0 c3p0.maxStatementsPerConnection = 0 In my understanding the prepared statements and statement pooling are two different things: Our hibernate stack uses prepared statements. Postgresql is caching the execution plan. Next time the same statement is used, postgresql reuses the execution plan.

Hibernate 5 的模块/包(modules/artifacts)

落爺英雄遲暮 提交于 2019-11-29 18:03:41
Hibernate 的功能被拆分成一系列的模块/包(modules/artifacts),其目的是为了对依赖进行独立(模块化)。 模块名称 说明 hibernate-core 这个是 Hibernate 的主要(main (core))模块。定义了 ORM 的特性和 API 以及一系列整合的 SPIs。 hibernate-envers Hibernate 历史的实体版本特性 hibernate-spatial Hibernate 的 Spatial/GIS 数据类型支持 hibernate-osgi Hibernate 支持运行 OSGi 容器 hibernate-agroal 整合 Agroal 连接池库到 Hibernate hibernate-c3p0 整合 C3P0 连接池库到 Hibernate hibernate-hikaricp 整合 HikariCP 连接池库到 Hibernate hibernate-vibur 整合 Vibur DBCP 连接池库到 Hibernate hibernate-proxool 整合 Proxool 连接池库到 Hibernate hibernate-jcache 整合 JCache 缓存特性到 Hibernate,使任何与其兼容的缓存实现能够成为 Hibernate 二级缓存的提供者 hibernate-ehcache 整合

Spring:IOC和DI注解开发

心已入冬 提交于 2019-11-29 15:45:50
1.Spring配置数据源 1.1 数据源(连接池)的作用 数据源(连接池)是提高程序性能如出现的 事先实例化数据源,初始化部分连接资源 使用连接资源时从数据源中获取 使用完毕后将连接资源归还给数据源 常见的数据源(连接池):DBCP、C3P0、BoneCP、Druid等 开发步骤 ①导入数据源的坐标和数据库驱动坐标 ②创建数据源对象 ③设置数据源的基本连接数据 ④使用数据源获取连接资源和归还连接资源 1.2 数据源的手动创建 ①导入c3p0和druid的坐标 <!-- C3P0连接池 --> < dependency > < groupId > c3p0 </ groupId > < artifactId > c3p0 </ artifactId > < version > 0.9.1.2 </ version > </ dependency > <!-- Druid连接池 --> < dependency > < groupId > com.alibaba </ groupId > < artifactId > druid </ artifactId > < version > 1.1.10 </ version > </ dependency > ①导入mysql数据库驱动坐标 <!-- mysql驱动 --> < dependency > < groupId > mysql

Reproduce com.mysql.jdbc.exceptions.jdbc4.CommunicationsException with a setup of Spring, hibernate and C3P0

自闭症网瘾萝莉.ら 提交于 2019-11-29 11:51:03
问题 I got this error from the production code: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was36940 seconds ago.The last packet sent successfully to the server was 36940 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the

Spring3.3 整合 Hibernate3、MyBatis3.2 配置多数据源/动态切换数据源 方法

て烟熏妆下的殇ゞ 提交于 2019-11-29 10:03:10
一、开篇 这里整合分别采用了Hibernate和MyBatis两大持久层框架,Hibernate主要完成增删改功能和一些单一的对象查询功能,MyBatis主要负责查询功能。所以在出来数据库方言的时候基本上没有什么问题,但唯一可能出现问题的就是在hibernate做添加操作生成主键策略的时候。因为我们都知道hibernate的数据库本地方言会针对不同的数据库采用不同的主键生成策略。 所以针对这一问题不得不采用自定义的主键生成策略,自己写一个主键生成器的表来维护主键生成方式或以及使用其他的方式来生成主键,从而避开利用hibernate默认提供的主键生成方式。 所以存在问题有: 怎样动态的切换数据库方言? 这个问题还没有解决,没有更多时间来研究。不过想想应该可以配置两个SessionFactory来实现,那又存在怎么样动态切换SessionFactory呢?!需要解决这个问题才行,而这里则演示怎么样动态切换DataSource数据源的方法。 二、代码演示 在演示开始之前你的项目已经成功的整合完成的情况下才行,如果你还不知道怎么使用Spring整合MyBatis和Spring整合Hibernate的话。建议参考之前的文章: MyBatis3整合Spring3、SpringMVC3 、 Struts2、Spring、Hibernate整合ExtJS

MSSQL JDBC driver won't connect to mirror failoverPartner on first connect

百般思念 提交于 2019-11-29 10:02:36
问题 I'm using C3P0 and the MS SQL JDBC 4 driver to automatically failover to a new database mirror when the database goes away. If it first connects to the principal DB, then the failover works and it switches seamlessly to the mirror DB. However, if the principal DB is down when the application starts, and the mirror DB is available to connect (tested with MSSQL Studio), then the application fails to start and fails to connect to the backup mirror. Here is the connection URL: jdbc:sqlserver:/