C3P0 database Connection pool-mode 1 manually created

Source: Internet
Author: User
Tags connection pooling

C3P0 is a common data connection pooling technology (provided by third parties)

is also based on the core class datasource.

Dbcputils.java

Package Com.itheima.b_dbcp;import Java.sql.connection;import Java.sql.sqlexception;import Org.apache.commons.dbcp.basicdatasource;public class Dbcputils {private static basicdatasource DataSource; static{try {//Manually create connection Pool DataSource = new Basicdatasource ();//Set parameters//* Basic Datasource.setdriverclassname ("Com.mysql.jdbc.Driver"); Datasource.seturl ("Jdbc:mysql://localhost:3306/day17");d atasource.setusername ("root");d Atasource.setpassword (" 1234 ");//* function datasource.setinitialsize (20); Number of initialization datasource.setmaxactive (50); Maximum number of connections Datasource.setmaxidle (30);//MAX idle number Datasource.setminidle (10)////* * * connection pool, use idle time to maintain link creation and destruction in connection pool} catch ( Exception e) {throw new RuntimeException (e);}} public static Connection getconnection () throws sqlexception{//get connection from Connection pool return datasource.getconnection ();}}

You can write a test class, test it yourself.

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.