-developed connection pools are mainly dbcp and c3p0. C3P0 Brief Introduction: C3P0 is an open source JDBC connection pool. It implements the data source and Jndi bindings, and supports the standard extensions of the JDBC3 specification and JDBC2. The open source project that uses it now has hibernate,spring and so on. DBCP Brief Introduction: DBCP (database co
First, the introduction of JAR packageSecond, Java code1 @Test2 Public voidTestxml ()throwsException {3 //creating the C3P0 Connection Pool core tool class4 //automatic loading src under c3p0 profile "C3p0-config.xml"5Combopooleddatasource DataSource =NewCombopooleddatasource ();//Use the default configuration6PreparedStatement pstmt =NULL;7
external IP address is unrealistic. In this way, there is a concept called connection pool. Because not every user needs to access the Internet at the same time, when a user needs to access the Internet, he can obtain an external IP address from the connection pool to access the Internet. When the user no longer needs to access the Internet, the IP address is put back in the connection pool and can be accessed by other users. The connection pool is mainly used to solve the problem of IP address
C3p0 can be used to connect to a database,
C3p0 can be used to connect to a database. Here, mysql is used as an example.
1. set parameters directly using the set method. Basic Method
ComboPooledDataSource dataSource = new ComboPooledDataSource ();DataSource. setDriverClass ("com. mysql. jdbc. Driver ");DataSource. setJdbcUrl ("jdbc: mysql: // localhost: 3306/mydb ");DataSource. setUser ("root ");DataSource.
The most common connection pooling technology, spring supports C3P0 connection pooling by default.Core class1. Combopooleddatasource ds;Introduced, C3P0 jar package2. Use a link pool to create a linkA) hard-coded mode Public voidTestcode ()throwsexception{//Create connection Pooling tool classCombopooleddatasource DataSource =NewCombopooleddatasource (); //Setting Connection ParametersDatasource.setjdbc
First import the Dbutils toolkit: Commons-dbutils-1.6.jar
And then import the C3P0 Toolkit: C3p0-0.9.1.2.jar
First create the C3P0 tool class:
Package star.july.util;
Import java.sql.Connection;
Import java.sql.SQLException;
Import Javax.sql.DataSource;
Import Com.mchange.v2.c3p0.ComboPooledDataSource;
p
java.sql.sqlexception:an attempt by a-client to checkout a Connection has-timed out. At Com.mchange.v2.sql.SqlUtils.toSQLException (sqlutils.java:106) at Com.mchange.v2.sql.SqlUtils.toSQLException ( SQLUTILS.JAVA:65) at Com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection ( c3p0pooledconnectionpool.java:527) at Com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection ( abstr
1.c3p0 OverviewC3P0 is an open source JDBC connection pool that implements the data source and Jndi bindings, and supports the standard extensions of the JDBC3 specification and JDBC2. The open source projects that currently use it are hibernate,spring and so on. 2.C3P0 Tool KitHttps://sourceforge.net/projects/c3p0/files/latest/download?source=filesImport jar pac
Label:Several common bugs for database connection pooling: 1. Warning: com[email protected]76c7022e--apparent DEADLOCK!!! Creating Emergency threads for unassigned pending tasks! October 01, 2016 6:28:24 PM Com.mchange.v2.async.threadpoolasynchronousrunner$deadlockdetector Run More than 80% is due to similar problems such as data connection configuration or databases . There is a problem with the configuration in ①jdbc.properties Driverclassname Url ② does not have a corresponding database.
Tags: style os io using Java ar for file dataC3P0 Database Connection Pool usage1. Copy jar package: C3p0-0.9.1.2.jar C3p0-0.9.1.2-jdk1.3.jar C3p0-oracle-thin-extras-0.9.1.2.jar (required by Oracle)2, write the preparation file in the SRC directory: c3p0-config.xml (the name can only be this)3, Class C3p0utilC3p0-confi
[Author]: KwuTo create a C3P0 data source, the actual development of the direct use of JDBC database connection is very small, generally using the form of data sources, C3P0 is open source data source, the actual project used a lot:1. Increase MAVEN Support2. Configurationc3p0, default configuration file C3p0-config.xml:3. Referencing a data source Package Com
In tomcat, JNDI uses the connection pool that comes with Tomcat.Discard the connection pool that comes with Tomcat. Use c3p0.Environment: Tomcat 5.5.20The following configuration is only applicable to Tomcat 5.5.x
The combination of JNDI and c3p0 is as follows:C3p0: http://nchc.dl.sourceforge.net/sourceforge/c3p0/c3p0
If you configure Hibernate to connect to the database environment, we can set up an environment that uses C3P0 data sources in Hibernate, for example, in the following operations.1). Import the jar package:Hibernate-release-4.2.4.final\lib\optional\c3p0\*.jar (There are usually 3 jar packages in it .) C3p0-0.9.2.1.jarHibernate-
If you configure Hibernate to connect to the database environment, we can set up the environment for using C3P0 data source in hibernate in the following operation. 1). Import the jar package:Hibernate-release-4.2.4.final\lib\optional\c3p0\*.jar (There are usually 3 jar packages in it .) C3p0-0.9.2.1.jarHibernate-c3p0-
The role of Dbutils:
Dbutils is an open source component of Apache, and for JDBC, dbutils can simplify heap JDBC operations because dbutils encapsulates the operation of JDBC.
main classes included in Dbutils:
1.QueryRunner class: Mainly for the operation of the database.
2.ResultSetHandler Interface: How to encapsulate the result set after the return of the Select.
3.Dbutils class: For closing resources and transaction processing.
C3p0 's intro
System InformationApplication logic is to query data with C3P0 to database and HTTP to return JSON data1 Initial test results prior to tuning JMeter test result
No.
Type
Original
Data bigger
1
500Connection
query/s
63q/s70q/s
2
Connections
255q/s
57q/sq/s
This data is the result of a database SELECT statement printed from the log of the program (which
The configuration file for the C3P0 database connection pool is placed in the SRC directory of Eclipse and the code is recognized.The contents of the C3P0 configuration file are as follows: For the specific configuration of C3P0, the file name is C3p0-config.xml: A problem was encountered when using the
What is a database connection pool:Use pools to manage connection, which can be reused with connection. With the pool, we don't have to create connection ourselves, but instead we get the connection object through the pool.When connection is finished, calling connection's close () method does not actually close the connection, but instead connection "returns" to the pool. The pool will be able to use this connection object again.Import dbutils Toolkit: Commons-dbutils-1.6.jarCommons-dbutils is a
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.