Database connection pool (set up a buffer pool for data Unified connection, now used by Enterprise development)

Source: Internet
Author: User

Database connection pool: (inside put a lot of connection data links, responsible for allocation, management, release database connection, reusable connection, but not new) for data Unified connection to establish a buffer pool, put a certain database connection, use in the buffer pool inside take, and then back to the buffer pool, and then use, do not need to create new;

---------------------------------------------------------------------------------------

Basic methods:


/*
* DBCP data Source: Need to use rack package Dbcp.jar
Add the jar package, rely on the Commons pool this rack package
Create a database connection pool
The common properties are set.
Get a connection to a database from a data source
* */

public void testdbcp () throws sqlexception{
Basicdatasource Datasource=null;
1. Creating an DBCP Data source instance

2. Specify the required properties for the data source instance
Driver=com.mysql.jdbc.driver
Jdbcurl=jdbc:mysql://localhost:3306/lxn

Datasource.setusername ("root");
Datasource.setpassword ("lxn123");
Datasource.seturl ("Jdbc:mysql://localhost:3306/lxn");
Datasource.setdriverclassname ("Com.mysql.jdbc.Driver");
System.out.println (Datasource.getusername ());
3. Get the connection from the data source
Connection connection=datasource.getconnection ();
System.out.println (connection);
}

Database connection pool (set up a buffer pool for data Unified connection, now used by Enterprise development)

Related Article

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.