getDataSourcec3p0Resource
private static void f3Resource() throws Exception { Connection conn = getDataSourcec3p0Resource().getConnection(); int res = executeUpdate(conn); System.out.println(res); } private static DataSource getDataSourcec3p0Resource() throws Exception { ComboPooledDataSource c3p0 = new ComboPooledDataSource("test"); return c3p0; } private static void f3() throws Exception { Connection conn = getDataSourceC3p0().getConnection(); int res = executeUpdate(conn); System.out.println(res); } public static DataSource getDataSourceC3p0() throws Exception { ComboPooledDataSource c3p0 = new ComboPooledDataSource(); c3p0.setDriverClass("com.mysql.jdbc.Driver"); c3p0.setJdbcUrl("jdbc:mysql://localhost:3306/jdbc"); c3p0.setUser("root"); c3p0.setPassword("root1010"); return c3p0; } private static int executeUpdate(Connection conn) { String sql = "UPDATE `user` set money=666 where id=?"; Object[] objs = new Object[]{"1"}; return JdbcUtils.executeUpdate(conn, sql, objs); }
11
<? Xml Version = "1.0" encoding = "UTF-8" ?> < C3p0-config > <-! Default configuration, if not specified using this configuration -> < default-config > < Property name = "the User " > the root </ Property > < Property name =" password " > XXX </ Property > < Property name =" the jdbcUrl " > JDBC: MySQL: // localhost: 3306 / JDBC </ Property > <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="checkoutTimeout">30000</property> <property name="idleConnectionTestPeriod">30</property> <property name="initialPoolSize">3</property> <property name="maxIdleTime">30</property> <property name="maxPoolSize">100</ Property > < Property name = "minPoolSize" > 2 </ Property > < Property name = "maxStatements" > 200 is </ Property > </ default-config > <-! Named configuration can be achieved by a method call - -> < the named config- name = "Test" > < Property name = "User" > the root </ Property > < Property name = "password">xxx</Property > < Property name = "jdbcUrl" > jdbc: MySQL: // localhost: 3306 / jdbc </ Property > < Property name = "driverClass" > com.mysql.jdbc.Driver </ Property > ! <- if the pool once the data is not enough growth in the number of connection -> < Property name = "acquireIncrement" > 5 </ Property > <-! the number of connections when you initialize the database connection pool -> < Property name = "initialPoolSize" >20</property> <! - a database connection pool maximum number of database connections -> < Property name = "the maxPoolSize" > 25 </ Property > <! - a database connection pool minimum number of database connections -> < Property name = "minPoolSize" > . 5 </ Property > </ the named-config > </ the c3p0-config >