configuration file
- The name must be c3p0-config.xml, otherwise it cannot be found; <default-config> is also indispensable.
-
Label name
<c3p0-config> <default-config> Specific configuration content </default-config> </c3p0-config>
Generally according to the above configuration, if there are more than one database can use the label.
sqlite configuration reference
<named-config name = "sqlite" > <property name="jdbcUrl">jdbc:sqlite:db_save_path</property> <property name="driverClass">org.sqlite.JDBC</property> <property name="checkoutTimeout">30000</property> <property name="idleConnectionTestPeriod">30</property> <property name="initialPoolSize">10</property> <property name="maxIdleTime">30</property> <property name="maxPoolSize">10</property> <property name="maxStatements">200</property> </named-config>
sqlite memory mode
The above configuration saves the database file to db_save_path. If the amount of data is small and does not need to be persisted to the hard disk, sqlite's memory database mode can be used.
<property name="jdbcUrl">jdbc:sqlite::memory:</property>
The memory name cannot be changed.
At this point, the database disappears immediately after the current database connection is closed. Each: memory: The database is a different database, that is to say, opening two database connections with the file name ": memory:" will create two independent internal databases.
If an in-memory database is specified by an unmodified ": memory" name, the database always has a private cache that is invisible to other connections. If the URI file name is used, the same memory database can be opened by connecting two or more databases.
Quote from SQLite profiling (6): Temporary files and memory databases
mysql configuration reference
<named-config name = "mysql" > <property name="jdbcUrl">jdbc:mysql://ipAddr:Port/dbName</property> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="user">username</property> <property name="password">password</property> <property name="checkoutTimeout">30000</property> <property name="idleConnectionTestPeriod">30</property> <property name="initialPoolSize">10</property> <property name="maxIdleTime">30</property> <property name="maxPoolSize">100</property> <property name="minPoolSize">10</property> <property name="maxStatements">200</property> </named-config>
A complete configuration of c3p0
<?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <default-config> <named-config name="mysql"> <!-- Basic attributes url,user,password --> <property name="url" value="jdbc:mysql://localhost:3306/regist_web?characterEncoding=UTF-8" /> <property name="username" value="root" /> <property name="password" value="123456" /> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <!-- Configuration initialization size, minimum, maximum --> <property name="initialSize" value="3" /> <property name="minIdle" value="3" /> <property name="maxActive" value="20" /> <!-- Configuration to get the connection waiting timeout time --> <property name="maxWait" value="60000" /> <!-- How often is the configuration interval detected to detect idle connections that need to be closed in milliseconds? --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- Configure the minimum lifetime of a connection in the pool in milliseconds --> <property name="minEvictableIdleTimeMillis" value="300000" /> <property name="validationQuery" value="SELECT 1" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <!-- open PSCache,And specify on each connection PSCache Size --> <property name="poolPreparedStatements" value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> </named-config> </default-config> </c3p0-config>
Two additional packages need to be introduced:
c3p0-0.9.2.1 jar and mchange-commons-java-0.2.3.4 jar
Lack of jar packages can cause errors
Reference comes from: