Java Code Examples for com.alibaba.druid.pool.DruidDataSource#setDriver()
The following examples show how to use
com.alibaba.druid.pool.DruidDataSource#setDriver() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MybatisConfig.java From java_server with MIT License | 6 votes |
private void druidSettings(DruidDataSource druidDataSource) throws Exception { druidDataSource.setMaxActive(1000); druidDataSource.setInitialSize(0); druidDataSource.setMinIdle(0); druidDataSource.setMaxWait(60000); druidDataSource.setPoolPreparedStatements(true); druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(100); druidDataSource.setTestOnBorrow(false); druidDataSource.setTestOnReturn(false); druidDataSource.setTestWhileIdle(true); druidDataSource.setTimeBetweenEvictionRunsMillis(6000); druidDataSource.setMinEvictableIdleTimeMillis(2520000); druidDataSource.setRemoveAbandoned(true); druidDataSource.setRemoveAbandonedTimeout(18000); druidDataSource.setLogAbandoned(true); druidDataSource.setFilters("mergeStat"); druidDataSource.setDriver(new Driver()); }
Example 2
Source File: ConnectionManager.java From es_data_export with Apache License 2.0 | 5 votes |
/** * 在构造函数初始化的时候获取数据库连接 * @throws Exception */ private ConnectionManager() throws Exception{ /** 获取属性文件中的值 **/ String jdbc_driver_library = Config.JDBC_CONFIG.getJdbc_driver_library(); String driverName = Config.JDBC_CONFIG.getJdbc_driver_class(); String url = Config.JDBC_CONFIG.getJdbc_connection_string(); String username = Config.JDBC_CONFIG.getJdbc_user(); String password = Config.JDBC_CONFIG.getJdbc_password(); /** 数据库连接池对象 **/ cpds = new DruidDataSource(); /** 设置数据库连接驱动 **/ //cpds.setDriverClassName(driverName); cpds.setDriver(DriverLoader.getDriverLoaderByName(jdbc_driver_library, driverName)); /** 设置数据库连接地址 **/ cpds.setUrl(url); /** 设置数据库连接用户名 **/ cpds.setUsername(username); /** 设置数据库连接密码 **/ cpds.setPassword(password); /** 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 **/ cpds.setTestWhileIdle(true); /*******最大连接池数量********/ cpds.setMaxActive(30); /*******初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时********/ cpds.setInitialSize(3); /** 超过30分钟开始关闭空闲连接 **/ cpds.setRemoveAbandonedTimeout(1800); /** 最大等待时间为60S 单位是毫秒**/ cpds.setMaxWait(60000); /**配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒**/ cpds.setTimeBetweenEvictionRunsMillis(30000); }