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