the configuration of c3p0 is divided into three types, namely1.setters setting individual configuration items individually2. A c3p0.properties file is provided under the Classpath3. A c3p0-config.xml file is provided under the Classpath1.setters setting individual configuration items individuallyThis is the most tediou
The configuration of C3P0 is divided into three types, namely1.setters setting individual configuration items individually2. A c3p0.properties file is provided under the Classpath3. A c3p0-config.xml file is provided under the Classpath1.setters setting individual configuration items individuallyThis is the most tediou
milliseconds#minEvictableIdleTimeMillis =#SQL查询, used to verify the connection taken out of the connection pool before the connection is returned to the callerValidationquery=select now ();#指明连接是否被空闲连接回收器 (if any) for inspection.#如果检测失败, the connection is removed from the pool.testwhileidle=true#指明是否在从池中取出连接前进行检验, if the test fails, the connection is removed from the pool and an attempt is taken to remove the other.Testonborrow=false#指明是否在归还到池中前进行检验Testonreturn=false#poolPreparedStatements =tru
http://sourceforge.net/projects/c3p0/files.
Figure 1
Step 2, add a reference to the project and find the lib/c3p0-0.9.2.1.jar In the downloaded file.
Step 3: Modify the hibernate. cfg. xml configuration file and add attributes. Hibernage will automatically find the content you configured and select c3p0 as the connection pool.
org.hibernate.
source and JNDI binding, support JDBC3 specifications and JDBC2 standard extension. Currently, open-source projects such as Hibernate and Spring do not have the function to automatically recycle idle connections. c3p0 has the function to automatically recycle idle connections. 3. Use of dbcp and C3P0. DBCP use ① import commons-dbcp2-2.1 and commons-pool2-2.4.1 into project
② The configuration file is dbcpc
No matter what persistence technology is used, you must access the database through data connections. In spring, data connections are obtained through data sources. In the past, data sources were generally provided by web application servers. In spring, you can not only obtain the data source of the application server through JNDI, but also directly configure the data source in the spring container. In addition, you can create a data source through code, in order to conduct a unit test without d
C3P0 configuration (we have a minimum of 5 connections):Where is the reason? The following classes are available in the Hibernate core package:It can be seen that hibernate's original ecology supports C3P0. So how do you get hibernate to recognize these configurations?To view the source code of the Org.hibernate.connection.ConnectionProviderFactory class in the Hibernate core package, you can see the follo
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 , etc.DBCP does not automatically reclaim idle connections, C3P0 has the ability to automatically reclaim idle connections Iii. use of DBCP and c3p01.DBCP Use ① will commons-dbcp2-2.1 and Span style= "margin:0px; padding:0px; Color:rgb (255,153,0) ">commons-pool2-2.4.1 Import project Span
C3p0Utils {// the function of the data source connection pool c3p0 does not need to establish a connection every time, wasting resources and waiting time, and placing the connection in the connection pool, when needed get // c3p0 connection pool can be automatically read through the configuration file c3p0-config.xml file related
user";Removeabandoned: Whether self-interruption, default is false;Removeabandonedtimeout: The data connection is automatically disconnected after a few seconds, and the value is provided when removeabandoned is true;Logabandoned: If the interrupt event is logged, the default is false;c3p0 Data SourceC3P0 is an open source JDBC data source implementation project that is published in the Lib directory with Hibernate and implements the Connection and s
SQLException {Connection con = null;try {con = dbpool.getinstance (). getconnection ();} catch (Exception e) {} finally {if (con! = null)Con.close ();}}}Method Two:Originally do not know to use C3P0 is so simple, I have been using the properties file to configure C3P0, but always connected to the database, and later debugging only found Combopooleddatasource Thi
is to use the configuration file3. Import the tool class you wrote (Initialize the connection pool to get the connection).4. The tool class used in DAO gets a connection or connection pool (some tool classes can automatically help us to create a connection).such as the Dbutil tool classConfiguration file:The configuration file for some key-value pairs in Java specifically provides such classes and file names.The suffix name of the Properties fileProp
1: The first method is very simple.
c3p0.driverClass=com.mysql.jdbc.Driverc3p0.jdbcUrl=jdbc:mysql://localhost:3308/databasec3p0.user=rootc3p0.password=root
File Name: c3p0. properties (put under the src directory)
// The program I wrote is relatively simple and can be used to test the execution configuration.
Package JDBC. mySQL; import Java. SQL. connection;
"); theCombopooleddatasource.setjdbcurl ("Jdbc:sqlserver://localhost:1433;databasename=mysql"); -Combopooleddatasource.setuser ("sa"); -Combopooleddatasource.setpassword ("1546873"); - +Combopooleddatasource.setacquireincrement (5);//you can set various properties of a connection pool - +conn=combopooleddatasource.getconnection (); A}Catch(propertyvetoexception e) { at //TODO auto-generated Catch block - e.printst
HIBERNATE5.0 has its own database connection pool, but regardless of performance and function is not as good as c3p0 (i novice, check the information learned), because before the bitter search resources are not willing, so write this article for like I suffer from search novice, for reference.
The steps to implement connection pooling for Hibernate5.0 integration c3p0 are as follows:
The first Step first
1)
user";Removeabandoned: Whether self-interruption, default is false;Removeabandonedtimeout: The data connection is automatically disconnected after a few seconds, and the value is provided when removeabandoned is true;Logabandoned: Whether to log interrupt events, default to FALSE;C3P0 data sourceC3P0 is an open source JDBC data source implementation project that is published in the Lib directory with Hibernate and implements the Connection and statem
1. Importing the JAR PackageC3p0-0.9.1.jarmchange-commons-java-0.2.3.4(Note: The jar package is a C3P0 database connection pool of auxiliary packages, no this package system will be reported when the boot ClassNotFoundException, This is the c3p0-0.9.2 version after the separation of the package, 0.9.1 when a package will be done)2. Get the connectionC3P0 is implemented in three ways.1. Write your own code t
C3P0 database connection pool,
Use the C3P0 database connection pool
1. 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 (oracle required)
2. Write the preparation file under the src directory:
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.