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







  • 相关阅读:
    咨询
    xcode技巧
    礼仪
    asi 网络框架
    iOS 开发问题 书籍 价值 改名 创业大赛app
    PS,UI,美工
    运营推广
    多线程 并发 文章
    手机技巧 文章
    javaScript 类文章
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276384.html
Copyright © 2011-2022 走看看