Establishing a server-to-database connection with C3P0

Source: Internet
Author: User


1: Build Web Service Project in MyEclipse
2: Build the Servlets package in the project
3: Create a new servlet file in the package (use the new Servlet method to save the configuration of the Web. XML step)
4: Import C3p0.jar and Mysql-connector.jar packages under the Webroot/web_inf/lib directory of the project, and build path
5: Create a new C3P0-CONFIG.CML file in the project SRC directory
6: Instantiate the connection DataSource DataSource =new combopooleddatasource ("helloc3p0") in the servlet;
attached C3P0-CONFIG.CML file
<c3p0-config><named-config name= "helloc3p0" ><!--Specify the basic properties of the connection source--><property name= "user" >root </property><property name= "password" >root</property><property name= "DriverClass" > Com.mysql.jdbc.driver</property><property name= "Jdbcurl" >jdbc:mysql:///otope</property><!- -Number of connections when initializing database connection pooling--><property name= "Initialpoolsize" >10</property><!-- Connection pooling number of new database connections created one time when no idle connection is available--><property name= "acquireincrement" >5</property><!--maximum idle time for the connection, , for 0 o'clock Forever connect--><property name= "MaxIdleTime" >30</property><!--the largest number of database connections in the database connection pool-->< Property Name= "Maxpoolsize" >50</property><!--the minimum number of database connections in the database connection pool--><property name= "Minpoolsize" >10</property></named-config></c3p0-config>

Implementing a connection method in a servlet
public void Testc3p0connect () throws Sqlexception{datasource DataSource =new combopooleddatasource ("helloc3p0"); System.out.println (Datasource.getconnection ());}



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.