Introduction to connection Pooling

Source: Internet
Author: User

1. What is a database connection pool        The database connection pool is responsible for allocating, managing, and freeing the database connection, which allows the application to reuse an existing database connection instead of re-establishing a database connection that has been idle for more than the maximum idle time to avoid missing database connections due to the absence of a database connection being freed.           2 , why to use the database connection pool
          Span style= "font-family: ' Microsoft yahei UI '; font-size:10.5pt; line-height:1.5 "> in the web application, the user needs to get a link to the database for each request. Database creation connections typically require a relatively large amount of resources and a longer creation time. Suppose the site is 10 10 million connections, great waste of database resources, and very easy to cause database server memory overflow, extension machine. So use the database connection pool here to avoid this problem.
3. Connection Pool configuration        1) Connection pool configuration                becauseall Tomcat projects share a connection pool configuration: In the Tomcat6->conf->context.xml filein whichto add between <context></context>:
      <Context>       <resource  name= "Jdbc/<span style=" Font-family:simsun; " >drp</span> "                  auth=" Container "                  type=" Javax.sql.DataSource "                  maxactive=" "                  maxidel=" 10 "                maxwait= "                  username=" root "password=" "          driverclassname=" Com.mysql.jdbc.Driver "          url= "Jdbc:mysql://127.0.0.1:3306/test"              >      </Resource>      
        2)then <web-app></web-app> in Web. Xml adds:
        <resource-ref>           <RES-REF-NAME>JDBC/DRP </res-ref-name>           <res-type> Javax.sql.DataSource </res-type>           <res-auth>Container</res-auth>         
     3) Get connection
        public static Connection getconnection () {             Connection conn = null;             PreparedStatement Pstmt=null;            ResultSet set = null;             try{                  Context ctx=new initialcontext ();                  Find DataSource                  DataSource ds= (DataSource) ctx.lookup ("JAVA:COMP/ENV/JDBC/DRP") through Jndi;                  conn = Ds.getconnection ();            } catch (ApplicationException e) {                  e.printstacktrace ();            }              return conn;        }
4) Ifeach Web project is configured independently with its own connection pool:put the XML content into a specific project directoryin the project directory of Meta-inf, create context.xml, content with the above.

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

Introduction to connection Pooling

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.