當前位置: 首頁>>代碼示例>>Java>>正文


Java DruidDataSource.init方法代碼示例

本文整理匯總了Java中com.alibaba.druid.pool.DruidDataSource.init方法的典型用法代碼示例。如果您正苦於以下問題:Java DruidDataSource.init方法的具體用法?Java DruidDataSource.init怎麽用?Java DruidDataSource.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.alibaba.druid.pool.DruidDataSource的用法示例。


在下文中一共展示了DruidDataSource.init方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mysqlDataSource

import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
public DataSource mysqlDataSource() throws Exception{
    DruidDataSource druidDataSource = new DruidDataSource();
    druidDataSource.setUrl(this.url);
    druidDataSource.setUsername(this.username);
    druidDataSource.setPassword(this.password);
    druidDataSource.setDriverClassName(this.driverClassName);
    druidDataSource.setInitialSize(this.initialSize);
    druidDataSource.setMaxActive(this.maxActive);
    druidDataSource.setMinIdle(this.minIdle);
    druidDataSource.setMaxWait(this.maxWait);
    druidDataSource.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis);
    druidDataSource.setMinEvictableIdleTimeMillis(this.minEvictableIdleTimeMillis);
    druidDataSource.setValidationQuery(this.validationQuery);
    druidDataSource.setTestWhileIdle(this.testWhileIdle);
    druidDataSource.setTestOnBorrow(this.testOnBorrow);
    druidDataSource.setTestOnReturn(this.testOnReturn);
    druidDataSource.setPoolPreparedStatements(this.poolPreparedStatements);
    druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(this.maxPoolPreparedStatementPerConnectionSize);
    druidDataSource.setFilters(this.filters);
    try {
        druidDataSource.setFilters("wall,stat");
        druidDataSource.setUseGlobalDataSourceStat(true);
        druidDataSource.init();
    } catch (Exception e) {
        throw new RuntimeException("load datasource error, dbProperties is :", e);
    }
    return druidDataSource;
}
 
開發者ID:YupaiTS,項目名稱:docs-manage,代碼行數:29,代碼來源:DruidProperties.java

示例2: init

import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
public void init() throws Exception{  
    System.out.println("**************init"); 
    MicroMetaDao dao=MicroMetaDao.getInstance();
    String sql="select * from nh_micro_dbconf";
    List<Map<String,Object>> infoList=dao.queryObjJoinByCondition(sql);
    for(Map<String,Object> row:infoList){
    	String metaKey=(String) row.get("meta_key");
    	String dataSourceClassName=(String) row.get("datasource_classname");
    	String dbUser=(String) row.get("db_user");
    	String dbPassWord=(String) row.get("db_password");
    	if(dbPassWord.startsWith("nhjm-")){
    		String temp=dbPassWord.substring(5);
    		dbPassWord=DESUtil.decrypt(temp);
    	}
    	String dbUrl=(String) row.get("db_url");
    	DruidDataSource ds=new DruidDataSource();
    	ds.setUsername(dbUser);
    	ds.setPassword(dbPassWord);
    	ds.setUrl(dbUrl);
    	ds.setFilters("stat");
    	ds.setMaxActive(10);
    	ds.setInitialSize(1);
    	ds.setMaxWait(60000);
    	ds.setMinIdle(1);
    	ds.setTimeBetweenEvictionRunsMillis(60000);
    	ds.setMinEvictableIdleTimeMillis(60000);
    	ds.setValidationQuery("SELECT 'x'");
    	ds.setTestWhileIdle(true);
    	ds.setTestOnBorrow(false);
    	ds.setTestOnReturn(false);
    	ds.setPoolPreparedStatements(true);
    	ds.setMaxPoolPreparedStatementPerConnectionSize(10);
    	ds.setDriverClassName(dataSourceClassName);
    	ds.init();
    	JdbcTemplate jdbcTemplate=new JdbcTemplate();
    	jdbcTemplate.setDataSource(ds);
    	MicroDbHolder.getDbHolder().put(metaKey, jdbcTemplate);
    }
}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:40,代碼來源:MicroDSInit.java

示例3: init

import com.alibaba.druid.pool.DruidDataSource; //導入方法依賴的package包/類
public void init() throws SQLException {
	logger.debug("初始化 DynamicDataSource {}...",this.dataSourceName);
	this.masterDataSource.init();
	Iterator<DruidDataSource> it = this.slaveDataSources.values().iterator();
	while (it.hasNext()) {
		DruidDataSource druidDataSource = (DruidDataSource) it.next();
		try {
			druidDataSource.init();
		} catch (SQLException e) {
			logger.warn("從庫{}初始化失敗", druidDataSource.getName());
		}
	}
}
 
開發者ID:halober,項目名稱:spring-boot-starter-dao,代碼行數:14,代碼來源:DynamicDataSource.java


注:本文中的com.alibaba.druid.pool.DruidDataSource.init方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。