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







  • 相关阅读:
    【[国家集训队]最长双回文串】
    【[国家集训队]Crash的数字表格 / JZPTAB】
    【YY的GCD】
    【于神之怒加强版】
    【[SDOI2015]约数个数和】
    【[TJOI2010]电影迷】
    【[SDOI2011]拦截导弹】
    【[SDOI2014]数表】
    linux系统编程之管道(三)
    linux系统编程之管道(二)
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276383.html
Copyright © 2011-2022 走看看