bonecp相关包
bonecp-0.7.0.jar
bonecp-provider-0.7.0.jar
bonecp-spring-0.7.0.jar
google-collections-1.0.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
2. 数据库相关配置bonecp-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<bonecp-config>
<default-config>
<property ></property>
<property name="jdbcUrl">jdbc:mysql://10.120.105.42:3306/db_tsp?characterEncoding=UTF-8&useUnicode=TRUE&autoReconnect=true</property>
<property name="username">zhangsan</property>
<property name="password">tsp123</property>
<property name="partitionCount">3</property>
<property name="maxConnectionsPerPartition">5</property>
<property name="minConnectionsPerPartition">1</property>
<property name="acquireIncrement">1</property>
<property name="idleConnectionTestPeriod">60</property>
</default-config>
</bonecp-config>
3. java 代码获取连接
public class ConnectionPool {
private static final Logger logger = LoggerFactory.getLogger(ConnectionPool.class);
private static BoneCP connectionPool = null;
private static Connection connection = null;
static {
try {
Class.forName("com.mysql.jdbc.Driver");
BoneCPConfig config = null;
config = new BoneCPConfig("bonecp-config.xml");
connectionPool = new BoneCP(config);
} catch(Exception e) {
logger.debug("连接数据库异常", e);
}
}
public static Connection getConnection() throws Exception {
if (connectionPool != null) {
connection = connectionPool.getConnection();
return connection;
}
throws ...
}
}