1: The first way is very simple
C3p0.driverclass=com.mysql.jdbc.driver
c3p0.jdbcurl=jdbc:mysql://localhost:3308/database
c3p0.user= Root
c3p0.password=root
File name: C3p0.properties (placed under the SRC directory)
The program I write is relatively simple and can be used
C3P0 database connection pool using 1, copy jar package: c3p0-0.9.1.2.jarc3p0-0.9.1.2-jdk1.3.jarc3p0-oracle-thin-extras-0.9.1.2.jar (oracle needs) 2, write preparation file under the src directory: c3p0-config.xml (name can only be this) 3, class C3P0Utilc3p0-config.xml content :? Xmlversion
C3P0 database connection po
Label:The jar package that needs to be prepared: The MySQL jar package Mysql-connector-java-5.1.39-bin is currently 5.1.39 Version:http://dev.mysql.com/downloads/connector/j/ C3P0 of 2 packages:https://sourceforge.net/projects/c3p0/C3p0-0.9.1.2.jar and C3p0-sources-0.9.1.2.jar Configuration file:
C3p0 connection pool template,
A connection pool is a technology used to create and manage a connection buffer pool. These connections are ready for use by any thread that needs them.
Now I am creating a template for the p3c0 connection pool.
First, p3c0 is open-source, so go to the official website to download the p3c0 jar package. Import data in the project and download the driver for your database connection.
The connection pool template code is
The default connection pool can be used in Hibernate. No matter the function and performance are not as good as C3PO (I have not tested it), C3P0 is an open source JDBC connection pool, it implements data source and JNDI binding and supports standard extensions of JDBC3 specifications and JDBC2. Currently, open-source projects using it include Hibernate and Spring.
C3P0 is a feature enhancement that makes i
Label:
Brief introduction
Usage evaluation
Project Home
DBCP
DBCP is a database connection pool that relies on the Jakarta Commons-pool object pooling mechanism. DBCP can be used directly in the application
You can set the maximum and minimum connections, the connection wait time, and so on, the basic function, the stability of the continuous operation of this connection pool is still possible, but the speed is slightly slower, under the
From: http://blog.sina.com.cn/s/blog_53345e4c0100b6zk.html
Official documentation:
Http://www.mchange.com/projects/c3p0/index.html
The preferredtestquery attribute is ignored. You cannot perform any operation on this test table. It will only be used for c3p0 testing.. Default: NULL -->
Retained, and continue to get the connection when getconnection () is called the next time. If it is set to trueAfter
c3p0 is an open source JDBC Connection pool that implements the data source and Jndi bindings to support the standard extensions of the JDBC3 specification and JDBC2. The open source projects that currently use it are hibernate,spring and so on. If you do not know what is the connection pool, you can first go to Baidu a bit. I understand, is a big pool, there are a lot of fish, each fish corresponding to a database connection, you get a fish you get a
Label:
Brief introduction
Usage evaluation
Project Home
DBCP
DBCP is a database connection pool that relies on the Jakarta Commons-pool object pooling mechanism. DBCP can be used directly in the application
You can set the maximum and minimum connections, the connection wait time, and so on, the basic function, the stability of the continuous operation of this connection pool is still possible, but the speed is slightly slower, under the pressu
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 tedious way, generally in the form of:Properties Pr
Hibernate uses the c3p0 data source,After configuring hibernate to connect to the database environment, we can perform the following operations to build the environment for using the c3p0 data source in hibernate. 1). Import the jar package:Hibernate-release-4.2.4.Final \ lib \ optional \ c3p0 \ *. jar (here there are generally 3 jar packages)
Label:
Brief introduction
Usage evaluation
Project Home
dbcp
DBCP is a database connection pool that relies on the Jakarta Commons-pool object pooling mechanism. DBCP can be used directly in the application using
can set maximum and minimum connections, connection wait time, etc., basic functions, The continued stability of this connection pool is still possible, but at a slightly slower rate, stability decreases under the
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
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 tedious way, generally in the form of:Properties Pr
= mydatasource.getconnection (); } catch (SQLException e) { E.printstacktrace (); } Return conn; }}Step three: Release the database connection and get the connection in the app.C3P0 Connection PoolC3P0 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. C3P0 is generally used with a frame such as hibernate
Official documents:http://www.mchange.com/projects/c3p0/index.html -- -- --Property Preferredtestquery will be ignored. You cannot do anything on this test sheet, it will be for C3P0 testing onlyUse. Default:null-->Reserved and continue trying to get the connection the next time you call Getconnection (). If set to true, then try toWhen a connection failure is obtained, the data source declares that it has
You need to import C3p0.jar to execute, and you need to import the appropriate MySQL database driver package.
Package com.yjpeng.c3p0;
Import java.beans.PropertyVetoException;Import java.io.FileNotFoundException;Import Java.io.FileReader;Import java.io.IOException;Import Java.io.InputStream;Import Java.io.Reader;Import java.sql.Connection;Import Java.sql.ResultSet;Import java.sql.SQLException;Import java.sql.Statement;Import java.util.Properties;
Impo
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.