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 ());}