c3p0

how to return a connection in c3p0

孤街浪徒 提交于 2019-12-22 03:48:26
问题 I am using c3p0 - ComboPooledDataSource. I am initializing once as below. private void init() { cpds = new ComboPooledDataSource(); cpds.setDriverClass(driverName); cpds.setJdbcUrl(url); cpds.setUser(userName); cpds.setPassword(pwd); } I am getting a connection from the pool as below public synchronized Connection getLocalConnection(String ipAddr) throws SQLException { return cpds.getConnection(); } But i am not sure whether its the right way to return the connection back to the pool when i

C3P0使用详解

你说的曾经没有我的故事 提交于 2019-12-21 16:40:51
定义: C3P0是一个开源的JDBC连接池,目前使用它的开源项目有 Hibernate,Spring 等。 数据库连接池的基本思想就是为数据库连接建立一个“缓冲池”。预先在缓冲池中放入一定数量的连接,当需要建立数据库连接时,只需从“缓冲池”中取出一个,使用完毕之后再放回去。我们可以通过设定连接池最大连接数来防止系统无尽的与数据库连接。获取一个连接,系统要在背后做很多消耗资源的事情,大多时候,创建连接的时间比执行sql语句的时间还要长。用户每次请求都需要向数据库获得链接,而数据库创建连接通常需要消耗相对较大的资源,创建时间也较长。 使用方法: 1.导入jar包:c3p0和mysql 2.配置xml文件 <?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <default-config>    <!--mysql数据库连接的各项参数--> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="jdbcUrl">jdbc:mysql://localhost:3306/mydb?characterEncoding=GBK</property> <property name="user">root</property> <property

JDBC connection timeout cannot reconnect

你离开我真会死。 提交于 2019-12-21 05:30:56
问题 I have my Spring Hibernate web application running on MySQL that gives me trouble. I have searched around and tried different configurations, read quite a few threads on this website, but it still pops up its smiling head. The error message is: Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 63,313,144 milliseconds ago. The last packet sent successfully to the server was 63,313,144 milliseconds ago. is longer than

PreparedStatement caching - what does it mean (how does it work)

限于喜欢 提交于 2019-12-21 03:46:33
问题 I'm using for example c3p0 with some defined "maxStatements" for preparedStatement caching. What does this caching really do? What kind of data it caches. On what level (db, application,..)? It will be nice to understand it from example. For example i have a query select * from sometable where somecolumn=? Now i send it in prepared statement that is not cached. And now i'm sending it and it is cached. What the difference. What happened in the first case and in the second. What is sent to DB

数据库连接池c3p0和dbcp

 ̄綄美尐妖づ 提交于 2019-12-20 12:54:01
现在常用的开源数据连接池主要有c3p0、dbcp和proxool三种,其中: hibernate开发组推荐使用c3p0; spring开发组推荐使用dbcp(dbcp连接池有weblogic连接池同样的问题,就是强行关闭连接或数据库重启后,无法reconnect,告诉连接被重置,这个设置可以解决); hibernate in action推荐使用c3p0和proxool; dbcp所需jar: commons-dbcp.jar、commons-pool.jar c3p0所需jar: c3p0-0.9.2.1.jar mchange-commons-java-0.2.3.4.jar proxool暂时没有接触到 C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展。目前使用它的开源项目有Hibernate,Spring等。 dbcp简介: DBCP(DataBase connection pool),数据库连接池。是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。单独使用dbcp需要3个包:common-dbcp.jar,common-pool.jar,common-collections.jar由于建立数据库连接是一个非常耗时耗资源的行为,所以通过连接池预先同数据库建立一些连接,放在内存中

SpringIOC和DI注解开发

邮差的信 提交于 2019-12-19 23:53:33
Spring<02>IOC和DI注解开发 1. Spring数据源 1.1 数据源(连接池)的作用(理解) 普通的JDBC连接数据库每次向数据库建立连接的时候都将connection加载到内存,再验证用户名等信息,这样会消耗一定的时间,每次的数据库连接,使用完后再断开,这样的方式会消耗大量的资源和时间。同时上千人访问的话将占用很多系统资源,导致服务器崩溃。 数据库连接池其实就是一个为数据库连接建立的一个“缓存池”,预先在数据库连接池中放入一定数量的连接。当需要数据库连接时,从连接池中拿就是了,用完再放回。数据库连接池负责分配、管理、释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是重新建立。 数据库连接池在初始化时将创建一定数量的数据库连接放到连接池中(initialPoolSize)。无论这些数据库连接是否被使用,连接池都将一直保证至少拥有这么多的连接数量。 连接池的最大数据库连接数量限定了这个连接池占有的最大连接数(maxPoolSize)。当应用程序向连接池请求的连接数超过最大连接数时,这些请求将加入到等待队列中。 数据库连接池相对于无连接池的优点 资源重用,避免频繁创建 事先实例化数据源,初始化部分连接资源 提高程序的性能 实现某一应用最大可用数据库连接数的限制避免某一应用独占所有的数据库资源 维护连接资源:使用连接资源时从数据源获取

Lot of SHOW TRANSACTION ISOLATION LEVEL queries in postgres

我只是一个虾纸丫 提交于 2019-12-19 13:50:11
问题 I am using Hibernate 4, PostgreSQL and C3P0. In my web application, after sometime I am getting multiple SHOW TRANSACTION ISOLATION LEVEL queries in database due to which my server gets hang. In my code all my connections are properly closed. Is it due to a connection leak? 回答1: You should also check the state of each query, if it's idle it's most likely nothing problematic. pg_stat_activity will show last query that was executed by each open connection. And c3p0 uses SHOW TRANSACTION

c3p0 maxIdleTime is same as wait_timeout of mysql?

那年仲夏 提交于 2019-12-19 06:08:05
问题 I am having an Spring MVC + Mysql (JDBC 4) + c3p0 0.9.2 project. In c3p0 maxIdleTime value is 240 (i.e 4 mins.) and wait_timeout in my.ini of Mysql to 30 seconds. According to c3p0 maxIdleTime: (Default: 0) Seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire. According to Mysql wait_timeout: The number of seconds the server waits for activity on a noninteractive connection before closing it. Now i am having some douts on this:

How to configure c3p0 in hibernate to auto-refresh stale DB connections

北城以北 提交于 2019-12-19 04:51:55
问题 I am using hibernate 3, c3p0 9.1.2, Oracle 11g in my application. If I restart the Oracle then the stale connections are not getting refresh and I am getting exception "java.sql.SQLRecoverableException: Closed Connection". Below is my hibernate.cfg.xml. I am a beginner in Hibernate API. Can you please suggest how to configure hibernate to automatically refresh the stale connections on a specified time. Here is my hibernate.cfg.xml oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@localhost

Spring configuration of C3P0 with Hibernate?

折月煮酒 提交于 2019-12-18 15:16:09
问题 I have a Spring/JPA application with Hibernate as the JPA provider. I've configured a C3P0 data source in Spring via: <bean id="myJdbcDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <!-- Connection properties --> <property name="driverClass" value="$DS{database.class}" /> <property name="jdbcUrl" value="$DS{database.url}" /> <property name="user" value="$DS{database.username}" /> <property name="password" value="$DS{database.password}" /> <!-- Pool