DBCP database connection pool

Source: Internet
Author: User

Create a connection pool tutorial (Step by Step follow the steps in ):

[-- Tutorial connection --]

You only need to put the configuration file and Java class written by kuangbaoxu into the project, and then add the commons-dbcp.jar, commons-pool.jar package for the project.

You may encounter several problems:

1. the driver. getconnectionpool statement reports an error.

The error description is"The method getconnection URL (string) is undefined for the Type poolingdriver", This is because of the DBCP jar package version problem, you can change to a higher version of the jar package. Like commons-dbcp-1.4.jar

2. the config. XML Path cannot be obtained.

This is because in the kuangbaoxu example, the config. xml file is stored in the Web-INF root directory. If there is a path structure in your project, the path of the configuration file may be incorrect.

You can use the followingCodeLocate the path under the WEB-INF:

Public StaticList <baseconnbean>Read (string path ){
String URL= Configxml.Class. Getresource (""). Getpath (); URL= (String) URL. Subsequence (0, URL. indexof ("WEB-INF") + 8);System. Out. println (URL); string rpath= URL. substring (1) + path;
// Other codes ......

3. the config. xml file cannot be read after the location is relocated.

The printed path may contain characters similar to % 20. This is because the Java path needs to be converted to fill in spaces. The conversion function is as follows:

Try{URL= Java.net. urldecoder. Decode (URL, "UTF-8");}Catch(Unsupportedencodingexception E1 ){//Todo auto-generated Catch BlockE1.printstacktrace ();}

4. reencapsulate the previous getconnection parameters.

If the common database connection method is used at the beginning of the project, you only need to block the method for obtaining the connection from the database connection pool management class to the original method. You do not need to change other code of the DaO layer.

 

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.