Configuration of c3p0 in spring

Source: Internet
Author: User
Database connections and usage should be frequently used in development and learning. However, there are many connection methods, for example, using the simplest JDBC Method, in addition, the database connection pool is more complex. Of course, DBCP connections are also used. Various methods have advantages and disadvantages of various methods. This is required based on the actual situation.

Database connections and usage should be frequently used in development and learning. However, there are many connection methods, for example, using the simplest JDBC Method, the database connection pool is also more complex. Of course, DBCP connections are also used. Various methods have advantages and disadvantages. This is required based on the actual situation.

The connection and use of databases should be frequently used in development and learning, but the connection

There are many ways, for example, using the simplest JDBC, there is a usage ratio

The more complicated one is the database connection pool, and of course there are connections using DBCP.

Method has the advantages and disadvantages of various methods. We have analyzed the advantages and disadvantages according to the actual situation.

For example, if a project is not a large project, and the hardware machines used

If it is not very good, it is estimated that there is no need to use the database connection pool. After all, the connection

The pool usually manages connections, which greatly occupies the running performance and efficiency of the machine.

(C3P0 is used in Spring framework development. The IDE tool is

"Myeclipse 9 ")

Here we will introduce how to use the C3P0 database connection pool in the project.

An open-source connection pool method that has been written and is highly efficient.

Both are simple and reasonable.

The first step is to build a project that requires C3P0. Of course, the simplest is also necessary.

Is to introduce the required Jar package:, This is not nutritious, I will not paste

Come out, be decisive About Baidu, and then, of course, "BuildPath", introduce the package

Then, write the C3P0 configuration file to the Spring configuration file.

It is called "Spring. xml" and is filled with the following characters:



Class = "com. mchange. v2.c3p0. ComboPooledDataSource">

Com. mysql. jdbc. Driver


Jdbc: mysql: // localhost: 3308/myoa?

UseUnicode = true & characterEncoding = UTF-

8 & zeroDateTimeBehavior = convertToNull


Root


Root



5




30




10




60




5




0




60




30




True




False



Detailed annotations are provided in this section. As long as there is a part of JAVA basics, you can understand them.

The rest is to use DataSource in Spring for calling and database connection.

The pool is connected. If it is only useful, you do not need to set it. It is already set by default.

Set.

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.