当前位置: 首页 > 工具软件 > BoneCP > 使用案例 >

bonecp mysql_BoneCP的简单使用

秦安怡
2023-12-01

package DBBasic;

import java.sql.Connection;

import java.sql.SQLException;

import com.jolbox.bonecp.*;

public class ConnBasic{

private static BoneCP connectionPool = null;

public ConnBasic(){

try {

Class.forName("com.mysql.jdbc.Driver");

} catch (Exception e) {

e.printStackTrace();

return;

}

BoneCPConfig config = new BoneCPConfig();

config.setJdbcUrl(UserPWmemory.getDBname());

config.setUsername( UserPWmemory.getUser());

config.setPassword(UserPWmemory.getPW());

config.setMinConnectionsPerPartition(5);

config.setMaxConnectionsPerPartition(10);

config.setPartitionCount(1);

try {

connectionPool = new BoneCP(config);

} catch (SQLException e) {

// TODO Auto-generated catch block

System.out.println(e.getMessage());

}

}

public static Connection getconn() {

Connection connection = null;

try {

connection = connectionPool.getConnection();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return connection;

}

}

 类似资料: