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







  • 相关阅读:
    RocketMQ Message hasn't been sent. Caused by No route info of this topic, test-topic
    Barrier
    WPF之资源
    WPF之命令
    WPF之事件
    WPF之属性
    多路Binding
    Binding的数据转换
    Binding的数据校验
    为Binding指定源的方法
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276384.html
Copyright © 2011-2022 走看看