apache-commons-dbcp

Implement Connection pooling in JDBC using apache dbcp [duplicate]

老子叫甜甜 提交于 2019-12-04 14:32:35
问题 This question already has answers here : Am I Using JDBC Connection Pooling? (4 answers) Closed 3 years ago . Is this Good Code to implement pooling? I want to implement this in my project which has 30 threads operating concurrently and each thread requires more than four connection for each request? Does this code work? import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Connection;

Does DBCP connection pool connection.close() return connection to pool

元气小坏坏 提交于 2019-12-04 09:16:43
Using BasicDataSource from DBCP if we do a getConnection() and in the finally block we close the connection does it really return the connection to the pool or does it close the connection. The snippet code I am checking is this try { Connection conn1 = getJdbcTemplate().getDataSource() .getConnection(); //Some code to call stored proc } catch (SQLException sqlEx) { throw sqlEx; } finally { try { if (conn != null) { conn.close(); } } catch (SQLException ex1) { throw ex1; } } I was checking the source code of BasicDataSource and I reached this wrapper class for the connection. private class

How to preinitialize DBCP connection pool on startup?

自闭症网瘾萝莉.ら 提交于 2019-12-04 08:27:54
The setup of my project is - Spring JDBC for persistence Apache DBCP 1.4 for connection pooling Mysql 5 on Linux Here is the log of my application that captures the interactions with the database. 2013-01-29 15:52:21,549 DEBUG http-bio-8080-exec-3 org.springframework.jdbc.core.JdbcTemplate - Executing SQL query [SELECT id from emp] 2013-01-29 15:52:21,558 DEBUG http-bio-8080-exec-3 org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource 2013-01-29 15:52:31,878 INFO http-bio-8080-exec-3 jdbc.connection - 1. Connection opened org.apache.commons.dbcp

Logging in DBCP

為{幸葍}努か 提交于 2019-12-03 17:35:36
问题 I'm using Apache Commons DBCP. There is a task to track the inner behavior of the DBCP - number of active and idle connections. I found out that DBCP lacks any such logging at all. Yes, tt is possible to write the code that outputs the status of the BasicDataSource when connection is borrowed from the pool. However there is no way to track the status of the BasicDataSource when connection is returned or closed, because connection object knows nothing about the pool. Any ideas? 回答1: I think

Question regarding org.apache.commons.dbcp.BasicDataSource

只谈情不闲聊 提交于 2019-12-03 17:17:57
I fixed some bug related to the way we were using BasicDataSource and though I understand part of it I still have some questions unanswered :) Problem: The application was not able to auto-connect to the database after a db failure. Application is using org.apache.commons.dbcp.BasicDataSource class as a TCP-connection pool for a JDBC connection to Oracle db. Fix: After some research I discovered that in BasicDataSource testOnBorrow and testOnreturn were not set. I provided the validation query to test connections. This fixed the problem Max no of connections in pool was set to 1 My

Postgres Error method org.postgresql.jdbc.PgConnection.createClob() is not implemented

元气小坏坏 提交于 2019-12-03 10:03:43
When I invoke createClob method using connection object as shown below: Clob clob = con.createClob(); Following exception is thrown: Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented. at org.postgresql.Driver.notImplemented(Driver.java:659) at org.postgresql.jdbc.PgConnection.createClob(PgConnection.java:1246) at org.apache.commons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868) at org.apache.commons.dbcp2.DelegatingConnection.createClob(DelegatingConnection.java:868) I`m using database

Logging in DBCP

心不动则不痛 提交于 2019-12-03 05:46:42
I'm using Apache Commons DBCP. There is a task to track the inner behavior of the DBCP - number of active and idle connections. I found out that DBCP lacks any such logging at all. Yes, tt is possible to write the code that outputs the status of the BasicDataSource when connection is borrowed from the pool. However there is no way to track the status of the BasicDataSource when connection is returned or closed, because connection object knows nothing about the pool. Any ideas? I think aspects may be the solution to your quandry. Check out: http://static.springsource.org/spring/docs/current

Tomcat Configuration using DBCP

♀尐吖头ヾ 提交于 2019-12-03 04:35:21
问题 We are getting a CommunicationsException (from DBCP) after iding for a while (a few hours). The error message (in the Exception) is at the end of this question - but I dont see wait_timeout defined in any of the configuration files. (Where should we look? Somewhere out of the tomcat/conf directory?). Secondly, as suggested by the Exception, where does one put the "Connector/J connection property 'autoReconnect=true'"? Here is the resource definition in the file conf/context.xml in tomcat set

Using encoded password for the datasource used in spring applicationContext.xml

拟墨画扇 提交于 2019-12-03 04:18:08
问题 I want to keep encoded password in my below mentioned springApplicationContext.xml Is there any way to achieve this? presently I have configured all properties using property-placeholder as shown below but the raw password is still open in my database.properties springApplicationContext.xml <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <beans:property name="driverClassName"><beans:value>${db.driverClassName}</beans:value></beans:property>

Tomcat Configuration using DBCP

流过昼夜 提交于 2019-12-02 17:46:07
We are getting a CommunicationsException (from DBCP) after iding for a while (a few hours). The error message (in the Exception) is at the end of this question - but I dont see wait_timeout defined in any of the configuration files. (Where should we look? Somewhere out of the tomcat/conf directory?). Secondly, as suggested by the Exception, where does one put the "Connector/J connection property 'autoReconnect=true'"? Here is the resource definition in the file conf/context.xml in tomcat set up: <Resource name="jdbc/TomcatResourceName" auth="Container" type="javax.sql.DataSource" maxActive=