• druid:java代码创建连接池


    PropertiesDB 是一个读取配置文件的类,也可以不用,每个参数直接用String代替。

    public DataSource dataSource(PropertiesDB propertiesDB) {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(propertiesDB.getUrl());
        dataSource.setDriverClassName(propertiesDB.getDriverClassName());
        dataSource.setUsername(propertiesDB.getUsername());
        dataSource.setPassword(propertiesDB.getPassword());
        if (StringUtils.isNotBlank(propertiesDB.getConnectionProperties())) {
          dataSource.setConnectionProperties(propertiesDB.getConnectionProperties());
        }
        dataSource.setInitialSize(propertiesDB.getInitialSize());
        dataSource.setMinIdle(propertiesDB.getMinIdle());
        dataSource.setMaxWait(propertiesDB.getMaxActive());
        dataSource.setMaxActive(propertiesDB.getMaxActive());
        dataSource.setTimeBetweenEvictionRunsMillis(propertiesDB.getTimeBetweenEvictionRunsMillis());
        dataSource.setMinEvictableIdleTimeMillis(propertiesDB.getMinEvictableIdleTimeMillis());
        dataSource.setTestWhileIdle(propertiesDB.getTestWhileIdle());
        if (StringUtils.isNotBlank(propertiesDB.getValidationQuery())) {
          dataSource.setValidationQuery(propertiesDB.getValidationQuery());
        }
        dataSource.setTestOnBorrow(propertiesDB.getTestOnBorrow());
        dataSource.setTestOnReturn(propertiesDB.getTestOnReturn());
        dataSource.setPoolPreparedStatements(propertiesDB.getPoolPreparedStatements());
        dataSource.setMaxPoolPreparedStatementPerConnectionSize(
            propertiesDB.getMaxPoolPreparedStatementPerConnectionSize());
        if (StringUtils.isNotBlank(propertiesDB.getFilters())) {
          try {
            dataSource.setFilters(propertiesDB.getFilters());
          } catch (SQLException e) {
            logger.error("初始化数据库连接池发生异常:{}", e.toString());
          }
        }
        return dataSource;
      }
  • 相关阅读:
    python-pycharm-django
    CSS
    django邮件
    访问user Model的三种方式
    weblogic升级war包(工作备忘)
    RestfulAPI_ 验证 与授权
    Restful API serialize相关
    scripy login captcha
    linux环境设置和核心命令
    java 调用JIRA api接口
  • 原文地址:https://www.cnblogs.com/huiy/p/9721951.html
Copyright © 2020-2023  润新知