Three configuration modes of c3p0
C3p0 is divided into three types, namely
1. Set each configuration item individually through the setters method
2. A c3p0.properties file is provided under the classpath
3. A c3p0-config.xml file is provided under the classpath
1. Set each configuration item individually through the setters method
This method is the most complicated, and the form is generally as follows:
ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDriverClass("com.mysql.jdbc.Driver"); cpds.setJdbcUrl("jdbc:mysql:///users"); cpds.setUser("root"); cpds.setPassword("123456");
2. A c3p0.properties file is provided under the classpath
The name of the file must be c3p0.properties, and the format of the configuration item in it is:
c3p0.driverClass=com.mysql.jdbc.Driver c3p0.jdbcUrl=jdbc:mysql:///users c3p0.user=root c3p0.password=123456
3. A c3p0-config.xml file is provided under the classpath
Here is a configuration template:
root 123456 com.mysql.jdbc.Driver jdbc:mysql:///users 10 30 100 10 root 123456 com.mysql.jdbc.Driver jdbc:mysql:///users 10 30 100 10
If you want to use default-config initialize the data source in the same way as the second, if you want to initialize the data source using the configuration in named-config, just use a ComboPooledDataSource constructor with parameters
ComboPooledDataSource cpds = new ComboPooledDataSource("myApp");