<dependencies> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.5</version> </dependency> </dependencies> <c3p0-config> <default-config> <property name="jdbcUrl">jdbc:mysql://localhost:3306/mydatabase</property> <property name="user">username</property> <property name="password">password</property> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="initialPoolSize">5</property> <property name="minPoolSize">5</property> <property name="maxPoolSize">20</property> <property name="maxStatements">100</property> </default-config> </c3p0-config> import com.mchange.v2.c3p0.ComboPooledDataSource; public class DatabaseAccess { private ComboPooledDataSource dataSource; public DatabaseAccess() { dataSource = new ComboPooledDataSource(); } public Connection getConnection() { Connection connection = null; try { connection = dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); } return connection; } }


上一篇:
下一篇:
切换中文