[C3P0] First article: Simple understanding C3P0

Source: Internet
Author: User

Preface

the translation is based on c3p0-0.9.5.1 version of the official documents, plus their own understanding, collation translation. The ability is limited, if the translation content is wrong or understanding has the deviation, also please everybody corrects!


What is c3p0

C3P0 is a very useful jar class library that is defined by the standard Extensions section of the JDBC3 specification and JDBC2 specification, making traditional JDBC more suitable for enterprise-level development. In version 0.9.5, C3P0 fully supports the JDBC4 specification.

C3P0 provides several useful services:

1, the way to get the database connection, from the traditional DriverManager-based JDBC driver acquisition into a new Javax.sql.DataSource mode acquisition.
2, Connection pool and PreparedStatement hidden behind DataSource, DataSource can "packaging" the traditional drive or any datasource without connection pool.

The library tries to get the right details:

1. C3P0 data sources are referenceable (and can be referenced) and serializable (serializable), so they are suitable for binding Jndi-based naming services.

2, when the connection and Statement removed from the connection pool are put back to the connection pool, Statement and resultset will be carefully cleaned up, Prevent the depletion of resources caused by laziness by simply cleaning up the connection resource management strategy.

3. The library uses a method defined by the JDBC2 and 3 specifications (which conflicts with the library author's own preferences). DataSource is written in the JavaBean specification, providing all the required attributes and many optional attributes (including some nonstandard attributes), without a bad constructor. All the internal interfaces defined by the JDBC specification are implemented (connectionpooldatasource,pooledconnection,connectionevent-generating connections,etc), You can mix c3p0 with third-party components (but not all C3P0 features are well compatible with external ConnectionPoolDataSource implementations).

C3P0 wants to provide a datasource implementation that is more suitable for large-scale "Java EE enterprise Applications". If you find a bug or fix a bug, please contact the official!


start -up use

C3P0 was originally designed to be simple to use, just put the jar file Lib/c3p0-0.9.5.1.jar in the application's valid classpath, and then create the DataSource:

[OPTIONAL] If you want to use the PreparedStatement pool, you must set the maxstatements and maxstatementsperconnection two parameters (the default value is 0):
Cpds.setmaxstatements (180);
whatever you want to do with DataSource, it will be supported by a connection pool initialized with default parameters. You can bind the data source to a Jndi service, or use it directly, depending on your preferences.
After you complete the task, you can clean up the data sources that you have created:
Cpds.close ();

This is the basic use! The rest is a matter of detail.


Prerequisites

c3p0-0.9.5.1 requires a Java Runtime environment of 1.6.x or more.


Jar Introduction

Put the files Lib/c3p0-0.9.5.1.jar and Lib/mchange-commons-java-0.2.10.jar under the program Classpath (or where other classloader can find them). That's it!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[C3P0] First article: Simple understanding C3P0

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.