当前位置: 首页>>代码示例>>Java>>正文


Java DruidDataSource.setUrl方法代码示例

本文整理汇总了Java中com.alibaba.druid.pool.DruidDataSource.setUrl方法的典型用法代码示例。如果您正苦于以下问题:Java DruidDataSource.setUrl方法的具体用法?Java DruidDataSource.setUrl怎么用?Java DruidDataSource.setUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.druid.pool.DruidDataSource的用法示例。


在下文中一共展示了DruidDataSource.setUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: studentDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(name = "studentDataSource")
public DataSource studentDataSource() {
	DruidDataSource dataSource = new DruidDataSource();
	dataSource.setUrl(studentUrl);
	dataSource.setUsername(studentUser);
	dataSource.setPassword(studentPassword);
	dataSource.setDriverClassName(studentDriverClass);
	//configuration
	dataSource.setInitialSize(initialSize);
	dataSource.setMinIdle(minIdle);
	dataSource.setMaxActive(maxActive);
	dataSource.setMaxWait(maxWait);
	dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
	dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
	dataSource.setValidationQuery(validationQuery);
	dataSource.setTestWhileIdle(testWhileIdle);
	dataSource.setTestOnBorrow(testOnBorrow);
	dataSource.setTestOnReturn(testOnReturn);
	dataSource.setPoolPreparedStatements(poolPreparedStatements);
	dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
	return dataSource;
}
 
开发者ID:ychaoyang,项目名称:autotest,代码行数:23,代码来源:StudentDataSourceConfig.java

示例2: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean
public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(databaseConfig.getUrl());
    datasource.setDriverClassName(databaseConfig.getDriverClassName());
    datasource.setUsername(databaseConfig.getUsername());
    datasource.setPassword(databaseConfig.getPassword());
    datasource.setInitialSize(databaseConfig.getInitialSize());
    datasource.setMinIdle(databaseConfig.getMinIdle());
    datasource.setMaxWait(databaseConfig.getMaxWait());
    datasource.setMaxActive(databaseConfig.getMaxActive());
    datasource.setMinEvictableIdleTimeMillis(databaseConfig.getMinEvictableIdleTimeMillis());
    try {
        datasource.setFilters("stat,wall,log4j2");
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return datasource;
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:20,代码来源:DruidDataSourceConfig.java

示例3: init

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
/**
 * 初始化操作
 *
 * @param modelName 模块名称
 * @param txConfig  配置信息
 */
@Override
public void init(String modelName, TccConfig txConfig) {
    dataSource = new DruidDataSource();
    final TccDbConfig tccDbConfig = txConfig.getTccDbConfig();
    dataSource.setUrl(tccDbConfig.getUrl());
    dataSource.setDriverClassName(tccDbConfig.getDriverClassName());
    dataSource.setUsername(tccDbConfig.getUsername());
    dataSource.setPassword(tccDbConfig.getPassword());
    dataSource.setInitialSize(tccDbConfig.getInitialSize());
    dataSource.setMaxActive(tccDbConfig.getMaxActive());
    dataSource.setMinIdle(tccDbConfig.getMinIdle());
    dataSource.setMaxWait(tccDbConfig.getMaxWait());
    dataSource.setValidationQuery(tccDbConfig.getValidationQuery());
    dataSource.setTestOnBorrow(tccDbConfig.getTestOnBorrow());
    dataSource.setTestOnReturn(tccDbConfig.getTestOnReturn());
    dataSource.setTestWhileIdle(tccDbConfig.getTestWhileIdle());
    dataSource.setPoolPreparedStatements(tccDbConfig.getPoolPreparedStatements());
    dataSource.setMaxPoolPreparedStatementPerConnectionSize(tccDbConfig.getMaxPoolPreparedStatementPerConnectionSize());
    this.tableName = RepositoryPathUtils.buildDbTableName(modelName);
    executeUpdate(SqlHelper.buildCreateTableSql(tccDbConfig.getDriverClassName(), tableName));
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:28,代码来源:JdbcCoordinatorRepository.java

示例4: register

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Override
public boolean register() {
    if (IsRegistered) {
        return HAS_REGISTERED;
    }

    DruidDataSource ds = new DruidDataSource();

    if (!StrUtil.isBlank(name)) {
        ds.setName(this.name);
    }

    ds.setUrl(jdbcURL);
    ds.setDriverClassName(jdbcDriver);
    ds.setUsername(jdbcUsername);
    ds.setPassword(jdbcPassword);

    ds.setMinIdle(minIdle);
    ds.setMaxActive(maxActive);
    ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    ds.setValidationQuery(validationQuery);

    ds.setTestWhileIdle(testWhileIdle);
    ds.setTestOnBorrow(testOnBorrow);
    ds.setTestOnReturn(testOnReturn);

    setDataSource(ds);
    setIsRegistered(HAS_REGISTERED);
    return HAS_REGISTERED;
}
 
开发者ID:xujiajun,项目名称:tastjava,代码行数:32,代码来源:DruidProvider.java

示例5: createDatasource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
/**
 * 创建多个数据源来模拟分布式服务环境
 * @param properties
 * @return
 */
private DataSource createDatasource(EasyTransTestProperties properties) {
	DruidDataSource ds = new DruidDataSource();
	ds.setUrl(properties.getUrl());
	ds.setUsername(properties.getUsername());
	ds.setPassword(properties.getPassword());
	ds.setMaxActive(10);
	ds.setInitialSize(1);
	ds.setMinIdle(1);
	ds.setPoolPreparedStatements(true);
	return ds;
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:17,代码来源:EasyTransTestConfiguration.java

示例6: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(initMethod="init",destroyMethod="close")
public DataSource dataSource(){
    DruidDataSource ds = new DruidDataSource();
    ds.setUrl(config.getUrl());
    ds.setUsername(config.getUsername());
    ds.setPassword(config.getPassword());
    ds.setInitialSize(ds.getInitialSize());
    ds.setMinIdle(config.getMinIdle());
    ds.setMaxActive(config.getMaxActive());
    ds.setMaxWait(config.getMaxWait());
    ds.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis()); // 关闭检测间隔 毫秒
    ds.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis()); // 一个连接的最小生存时间
    ds.setValidationQuery("SELECT 'x'");
    ds.setTestWhileIdle(config.isTestWhileIdle());
    ds.setTestOnBorrow(config.isTestOnBorrow());
    ds.setTestOnReturn(config.isTestOnReturn());
    ds.setPoolPreparedStatements(config.isPoolPreparedStatements());
    ds.setMaxPoolPreparedStatementPerConnectionSize(config.getMaxPoolPreparedStatementPerConnectionSize());
    ds.setRemoveAbandoned(config.isRemoveAbandoned());
    ds.setRemoveAbandonedTimeout(config.getRemoveAbandonedTimeout());
    ds.setLogAbandoned(config.isLogAbandoned());
    ds.setTimeBetweenLogStatsMillis(config.getTimeBetweenLogStatsMillis());
    ds.setPhyTimeoutMillis(config.getPhyTimeoutMillis());
    ds.setMaxEvictableIdleTimeMillis(config.getMaxEvictableIdleTimeMillis());
    ds.setDbType("mysql");
    try {
        ds.setFilters("stat,slf4j");
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return ds ; 
}
 
开发者ID:eXcellme,项目名称:eds,代码行数:33,代码来源:DatabaseConfig.java

示例7: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean
public DataSource dataSource(DataSourceProperties properties){
    logger.debug("DataSource: url: {} ; username:{}",properties.getUrl(), properties.getUsername());
    DruidDataSource druidDataSource = new DruidDataSource();
    druidDataSource.setName(properties.getName());
    druidDataSource.setUsername(properties.getUsername());
    druidDataSource.setPassword(properties.getPassword());
    druidDataSource.setUrl(properties.getUrl());
    return druidDataSource;
}
 
开发者ID:WinstonZheng,项目名称:wtem,代码行数:11,代码来源:MybatisConfig.java

示例8: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean
public DataSource dataSource(){
	DruidDataSource druidDataSource=new DruidDataSource()   ;
	druidDataSource.setDriverClassName(driverClass);
	druidDataSource.setUrl(jdbcUrl);
	druidDataSource.setUsername(username);
	druidDataSource.setPassword(password);
	return druidDataSource ;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:10,代码来源:DataSourceConfig.java

示例9: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(name="dataSource")
//标志这个 Bean 如果在多个同类 Bean 候选时,该 Bean 优先被考虑。「多数据源配置的时候注意,必须要有一个主数据源,用 @Primary 标志该 Bean
@Primary
public DataSource dataSource(){
	DruidDataSource druidDataSource = new DruidDataSource();
	druidDataSource.setUrl(url);
	druidDataSource.setUsername(user);
	druidDataSource.setPassword(password);
	druidDataSource.setDriverClassName(driverClass);
	return druidDataSource;
	
}
 
开发者ID:viakiba,项目名称:springboot,代码行数:13,代码来源:DruidDataSourceConfig.java

示例10: dataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource dataSource() throws SQLException {
    if (StringUtils.isEmpty(propertyResolver.getProperty("url"))) {
        System.out.println("Your database connection pool configuration is incorrect!"
                + " Please check your Spring profile, current profiles are:"
                + Arrays.toString(environment.getActiveProfiles()));
        throw new ApplicationContextException(
                "Database connection pool is not configured correctly");
    }
    DruidDataSource druidDataSource = new DruidDataSource();
    druidDataSource.setDriverClassName(propertyResolver.getProperty("driver-class-name"));
    druidDataSource.setUrl(propertyResolver.getProperty("url"));
    druidDataSource.setUsername(propertyResolver.getProperty("username"));
    druidDataSource.setPassword(propertyResolver.getProperty("password"));
    druidDataSource.setInitialSize(Integer.parseInt(propertyResolver.getProperty("initialSize")));
    druidDataSource.setMinIdle(Integer.parseInt(propertyResolver.getProperty("minIdle")));
    druidDataSource.setMaxActive(Integer.parseInt(propertyResolver.getProperty("maxActive")));
    druidDataSource.setMaxWait(Integer.parseInt(propertyResolver.getProperty("maxWait")));
    druidDataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(propertyResolver.getProperty("timeBetweenEvictionRunsMillis")));
    druidDataSource.setMinEvictableIdleTimeMillis(Long.parseLong(propertyResolver.getProperty("minEvictableIdleTimeMillis")));
    druidDataSource.setValidationQuery(propertyResolver.getProperty("validationQuery"));
    druidDataSource.setTestWhileIdle(Boolean.parseBoolean(propertyResolver.getProperty("testWhileIdle")));
    druidDataSource.setTestOnBorrow(Boolean.parseBoolean(propertyResolver.getProperty("testOnBorrow")));
    druidDataSource.setTestOnReturn(Boolean.parseBoolean(propertyResolver.getProperty("testOnReturn")));
    druidDataSource.setPoolPreparedStatements(Boolean.parseBoolean(propertyResolver.getProperty("poolPreparedStatements")));
    druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(Integer.parseInt(propertyResolver.getProperty("maxPoolPreparedStatementPerConnectionSize")));
    druidDataSource.setFilters(propertyResolver.getProperty("filters"));
    return druidDataSource;
}
 
开发者ID:ywtnhm,项目名称:pay-xxpay-master,代码行数:30,代码来源:DruidDataSourceConfig.java

示例11: initialize

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@SuppressWarnings("static-access")
public void initialize() throws SQLException{
       if (this.url == null) {
           throw new SQLException("DBPool could not be created: DB URL cannot be null");
       }

       if (this.driver == null) {
           throw new SQLException("DBPool driver could not be created: DB driver class name cannot be null!");
       }

       if (this.maxConnections < 0) {
           throw new SQLException("DBPool maxConnectins could not be created: Max connections must be greater than zero!");
       }

       datasource = new DruidDataSource();
       try{
           datasource.setDriverClassName(this.driver);
       } catch (Exception e) {
           logger.error("Problem setting driver class name on datasource: {}" + e.getMessage(), e);
       }

       datasource.setUrl(this.url);
       datasource.setUsername(this.user);
       datasource.setPassword(this.password);
       datasource.setMaxActive(this.maxConnections);
       datasource.setMinIdle(1);
       datasource.setMaxWait(0);
       datasource.setMaxPoolPreparedStatementPerConnectionSize(this.DEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTION);

       if (this.validationQuery != null) {
           datasource.setValidationQuery(this.validationQuery);
           if(!this.validateOnCheckout)
               datasource.setTestOnReturn(true);
           else
               datasource.setTestOnBorrow(true);
           datasource.setValidationQueryTimeout(this.idleConnectionValidationSeconds);
       }
   }
 
开发者ID:wjggwm,项目名称:webside,代码行数:39,代码来源:DruidConnectionProviderManager.java

示例12: 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

示例13: masterDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Bean(name="masterDataSource")
//标志这个 Bean 如果在多个同类 Bean 候选时,该 Bean 优先被考虑。「多数据源配置的时候注意,必须要有一个主数据源,用 @Primary 标志该 Bean
@Primary
public DataSource masterDataSource(){
	DruidDataSource druidDataSource = new DruidDataSource();
	druidDataSource.setUrl(url);
	druidDataSource.setUsername(user);
	druidDataSource.setPassword(password);
	druidDataSource.setDriverClassName(driverClass);
	return druidDataSource;
	
}
 
开发者ID:viakiba,项目名称:springboot,代码行数:13,代码来源:MasterDataSourceConfig.java

示例14: configDruid

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
private void configDruid(DruidDataSource dataSource, DruidProperties properties) {
    dataSource.setUrl(url);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    if (properties.getInitialSize() > 0) {
        dataSource.setInitialSize(properties.getInitialSize());
    }
    if (properties.getMinIdle() > 0) {
        dataSource.setMinIdle(properties.getMinIdle());
    }
    if (properties.getMaxActive() > 0) {
        dataSource.setMaxActive(properties.getMaxActive());
    }
    if (properties.getMaxWait() > 0 ){
        dataSource.setMaxWait(properties.getMaxWait());
    }
    if (properties.getTimeBetweenEvictionRunsMillis() > 0l){
        dataSource.setTimeBetweenEvictionRunsMillis(properties.getTimeBetweenEvictionRunsMillis());
    }
    if (properties.getMaxPoolPreparedStatementPerConnectionSize() > 0 ){
        dataSource.setMaxPoolPreparedStatementPerConnectionSize(properties.getMaxPoolPreparedStatementPerConnectionSize());
    }
    if (properties.getValidationQueryTimeout() > 0 ){
        dataSource.setValidationQueryTimeout(properties.getValidationQueryTimeout());
    }
    if (properties.getMinEvictableIdleTimeMillis() > 0l){
        dataSource.setMinEvictableIdleTimeMillis(properties.getMinEvictableIdleTimeMillis());
    }
    dataSource.setValidationQuery(properties.getValidationQuery());
    dataSource.setTestOnReturn(properties.getTestOnReturn());
    dataSource.setTestOnBorrow(properties.isTestOnBorrow());
    dataSource.setTestWhileIdle(properties.getTestWhileIdle());
    dataSource.setPoolPreparedStatements(properties.getPoolPreparedStatements());
    dataSource.setConnectProperties(properties.getConnectionProperties());
    try {
        dataSource.setFilters(properties.getFilters());
    } catch (SQLException e) {
        throw new IllegalArgumentException("please check your spring.datasource.druid.filters property.", e);
    }
}
 
开发者ID:cuisongliu,项目名称:druid-boot-starter,代码行数:41,代码来源:DruidAutoConfiguration.java

示例15: initDataSource

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
private void initDataSource(){
	dataSource=new DruidDataSource();
	dataSource.setAsyncCloseConnectionEnable(true);
	dataSource.setBreakAfterAcquireFailure(true);
	dataSource.setDefaultAutoCommit(true);
	dataSource.setDefaultReadOnly(true);
	dataSource.setDriverClassName(args.getJdbcDriver());
	dataSource.setEnable(true);
	dataSource.setPassword(args.getPassword());
	dataSource.setTestOnBorrow(true);
	dataSource.setTestOnReturn(true);
	dataSource.setTestWhileIdle(true);
	dataSource.setUrl(args.getJdbcUrl());
	dataSource.setUsername(args.getUser());
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:16,代码来源:RehashLauncher.java


注:本文中的com.alibaba.druid.pool.DruidDataSource.setUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。