BoneCP的简单使用

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;
	}
}

  需要一些外包

posted @ 2013-07-11 10:43  skyko  阅读(795)  评论(0编辑  收藏  举报