zoukankan      html  css  js  c++  java
  • DBCP 数据库连接池配置

     pheonix_jdbc.properties 文件

     driverClassName=org.apache.phoenix.jdbc.PhoenixDriver
    url=jdbc:phoenix:10.1.20.129,10.1.20.128,10.1.20.44:2181
    username=user
    password=pass
    initialSize=10
    maxIdle=20
    minIdle=5
    maxActive=50
    logAbandoned=true
    removeAbandoned=true
    removeAbandonedTimeout=180
    maxWait=1000


    Java 代码


    public class PhoenixQueryUtils {
    
        private static BasicDataSource dataSource = null; 
    
        private PhoenixQueryUtils() {
        }
    
        private synchronized static void init() throws SQLException {
            if (dataSource != null) {
                try {
                    dataSource.close();
                } catch (SQLException ex) {
                    DbUtils.printStackTrace(ex);
                }
            }
            dataSource = null;
            InputStream in = Object.class.getResourceAsStream("/pheonix_jdbc.properties");
            Properties props = new Properties();
            try {
                props.load(in);
                dataSource = BasicDataSourceFactory.createDataSource(props); 
            } catch (IOException ex) {
                throw new SQLException(ex);
            } catch (Exception ex) {
                throw new SQLException(ex);
            }
    
        } 
        public static synchronized Connection getConnection() throws SQLException, IOException, Exception {
            Connection conn = null;
            if (dataSource == null) {
                init();
            }
            if (dataSource != null) {
                conn = dataSource.getConnection();
            }
            return conn;
        }
    
    }







  • 相关阅读:
    Cisco 交换机配置的基本命令
    Mysql读写分离方案-Amoeba环境部署记录
    centos7下部署zabbix3.4+grafana
    Docker
    Linux 安装源码软件
    mysql 日志
    mysql导出导入数据
    mysql 数据库的备份和还原
    Mysql 数据库管理
    英语单词
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276383.html
Copyright © 2011-2022 走看看