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


Java BasicDataSource.setUrl方法代码示例

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


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

示例1: buildDataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
/**
 * 通过基础配置信息构建DBCP数据源信息.
 * @param driver 数据库连接的JDBC驱动
 * @param url 数据库连接的url
 * @param user 数据库连接的用户名
 * @param password 数据库连接的密码
 */
public BasicDataSource buildDataSource(String driver, String url, String user, String password) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setUrl(url);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    return dataSource;
}
 
开发者ID:blinkfox,项目名称:adept,代码行数:16,代码来源:DbcpDataSourceConfig.java

示例2: register

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public boolean register(JdbcVo conf) {
    boolean isOk = true;
    try {
        BasicDataSource bds = new BasicDataSource();
        bds.setDriverClassName(conf.getDriverClass());
        bds.setUrl(conf.getUrl());
        bds.setUsername(conf.getUserName());
        bds.setPassword(conf.getPassword());
        bds.setInitialSize(conf.getInitialSize());
        bds.setMaxActive(conf.getMaxActive());
        bds.setMaxIdle(conf.getMaxIdle());
        bds.setMinIdle(conf.getMinIdle());
        cmap.put(conf.getKey(), bds);
    } catch (Exception e) {
        LoggerFactory.getLogger().error("[db container initThreadPool key " + conf.getKey() + " datasource error!]", e);
        isOk = false;
    }
    return isOk;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:20,代码来源:DataSourceContainer.java

示例3: getJobEventRdbConfiguration

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
/**
 * 获取作业数据库事件配置.
 *
 * @return 作业数据库事件配置
 */
public Optional<JobEventRdbConfiguration> getJobEventRdbConfiguration() {
    String driver = getValue(EnvironmentArgument.EVENT_TRACE_RDB_DRIVER);
    String url = getValue(EnvironmentArgument.EVENT_TRACE_RDB_URL);
    String username = getValue(EnvironmentArgument.EVENT_TRACE_RDB_USERNAME);
    String password = getValue(EnvironmentArgument.EVENT_TRACE_RDB_PASSWORD);
    if (!Strings.isNullOrEmpty(driver) && !Strings.isNullOrEmpty(url) && !Strings.isNullOrEmpty(username)) {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return Optional.of(new JobEventRdbConfiguration(dataSource));
    }
    return Optional.absent();
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:21,代码来源:BootstrapEnvironment.java

示例4: getJdbcTemplate

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@Provides
@Singleton
public NamedParameterJdbcTemplate getJdbcTemplate(
        @Named("jdbc.driver") String driver,
        @Named("jdbc.username") String username,
        @Named("jdbc.password") String password,
        @Named("jdbc.url") String url,
        @Named("jdbc.maxActive") Integer maxActive,
        @Named("jdbc.maxIdle") Integer maxIdle,
        @Named("jdbc.initialSize") Integer initialSize,
        @Named("jdbc.validationQuery") String validationQuery) {
    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName(driver);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setUrl(url);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setInitialSize(initialSize);
    dataSource.setValidationQuery(validationQuery);

    return new NamedParameterJdbcTemplate(dataSource);
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:25,代码来源:WayfGuiceModule.java

示例5: JdbcStoragePlugin

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public JdbcStoragePlugin(JdbcStorageConfig config, DrillbitContext context, String name) {
  this.context = context;
  this.config = config;
  this.name = name;
  BasicDataSource source = new BasicDataSource();
  source.setDriverClassName(config.getDriver());
  source.setUrl(config.getUrl());

  if (config.getUsername() != null) {
    source.setUsername(config.getUsername());
  }

  if (config.getPassword() != null) {
    source.setPassword(config.getPassword());
  }

  this.source = source;
  this.dialect = JdbcSchema.createDialect(source);
  this.convention = new DrillJdbcConvention(dialect, name);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:21,代码来源:JdbcStoragePlugin.java

示例6: getDataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public static DataSource getDataSource() {
    BasicDataSource ds = new BasicDataSource();
    if (StringUtil.isNotEmpty(driver)) {
        ds.setDriverClassName(driver);
    }
    if (StringUtil.isNotEmpty(url)) {
        ds.setUrl(url);
    }
    if (StringUtil.isNotEmpty(username)) {
        ds.setUsername(username);
    }
    if (StringUtil.isNotEmpty(password)) {
        ds.setPassword(password);
    }
    if (maxActive != 0) {
        ds.setMaxActive(maxActive);
    }
    if (maxIdle != 0) {
        ds.setMaxIdle(maxIdle);
    }
    return ds;
}
 
开发者ID:thinkhoon,项目名称:tkhoon,代码行数:23,代码来源:DBHelper.java

示例7: createBasicDataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
/**
 * createBasicDataSource
 *
 * @param dbDriver
 *            database driver
 * @param dbUser
 *            database user
 * @param dbPwd
 *            database password
 * @param dbURL
 *            database url
 * @return BasicDataSource based on parameter inputs
 */
public BasicDataSource createBasicDataSource(String dbDriver, String dbUser, String dbPwd, String dbURL) {
    BasicDataSource d = new BasicDataSource();
    d.setDriverClassName(dbDriver);
    d.setUsername(dbUser);
    d.setPassword(dbPwd);
    d.setUrl(dbURL);

    try {
        Class.forName(ConfigurationManager.getInstance().getDatabaseDriver());
    } catch (ClassNotFoundException e) {
        log.error("Unable to initialize database driver.");
    }

    return d;
}
 
开发者ID:AgileTestingFramework,项目名称:atf-toolbox-java,代码行数:29,代码来源:DatabaseAutomationManager.java

示例8: createDb

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private static BasicDataSource createDb(String dbName, String basePath, String[] files) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.h2.Driver");
    dataSource.setUsername("username");
    dataSource.setPassword("password");
    dataSource.setUrl("jdbc:h2:mem:test" + dbName);
    try (Connection connection = dataSource.getConnection()) {
        for (String f : files) {
            String scriptPath = Paths.get(basePath, f).toString();
            try (Statement statement = connection.createStatement()  ) {
                statement.executeUpdate("RUNSCRIPT FROM '" + scriptPath + "'");   //NOSONAR
            }
        }
    } catch (SQLException e) {
        log.error("Error while creating the in-memory H2 Database.", e);
    }
    return dataSource;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:19,代码来源:MockInitialContextFactory.java

示例9: test

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
    try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
        server.start();
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setUrl("jdbc:herddb:server:localhost:7000?");
        dataSource.setDriverClassName(Driver.class.getName());
        try (Connection connection = dataSource.getConnection();
                Statement statement = connection.createStatement();
                ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES")) {
            int count = 0;
            while (rs.next()) {
                System.out.println("table: " + rs.getString(1));
                count++;
            }
            assertTrue(count > 0);
        }
        dataSource.close();

    }
}
 
开发者ID:diennea,项目名称:herddb,代码行数:22,代码来源:CommonsDBCPTest.java

示例10: dataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@Bean
public DataSource dataSource() throws URISyntaxException {
    URI dbUri = new URI(System.getenv("DATABASE_URL"));

    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName("org.postgresql.Driver");
    basicDataSource.setUrl(dbUrl);
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);

    return basicDataSource;
}
 
开发者ID:Nanofus,项目名称:Photocan,代码行数:17,代码来源:ProdProfile.java

示例11: createDatabaseObject

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private Database createDatabaseObject(Module module) {
  final Properties props = OBPropertiesProvider.getInstance().getOpenbravoProperties();

  final BasicDataSource ds = new BasicDataSource();
  ds.setDriverClassName(props.getProperty("bbdd.driver"));
  if (props.getProperty("bbdd.rdbms").equals("POSTGRE")) {
    ds.setUrl(props.getProperty("bbdd.url") + "/" + props.getProperty("bbdd.sid"));
  } else {
    ds.setUrl(props.getProperty("bbdd.url"));
  }
  ds.setUsername(props.getProperty("bbdd.user"));
  ds.setPassword(props.getProperty("bbdd.password"));
  Platform platform = PlatformFactory.createNewPlatformInstance(ds);
  platform.getModelLoader().setOnlyLoadTableColumns(true);

  if (module != null) {
    final String dbPrefix = module.getModuleDBPrefixList().get(0).getName();
    final ExcludeFilter filter = DBSMOBUtil.getInstance().getExcludeFilter(
        new File(props.getProperty("source.path")));
    filter.addPrefix(dbPrefix);

    return platform.loadModelFromDatabase(filter, dbPrefix, true, module.getId());
  }

  return platform.loadModelFromDatabase(null);
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:27,代码来源:SystemValidatorTest.java

示例12: _get

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private static BasicDataSource _get(String D, String username, String passwd, String url, int N) {
  BasicDataSource external = new BasicDataSource();
  external.setDriverClassName(D.trim());

  if (!X.isEmpty(username)) {
    external.setUsername(username.trim());
  }
  if (!X.isEmpty(passwd)) {
    external.setPassword(passwd.trim());
  }

  external.setUrl(url.trim());

  external.setMaxActive(N);
  external.setDefaultAutoCommit(true);
  external.setMaxIdle(N);
  external.setMaxWait(MAX_WAIT_TIME);
  external.setDefaultAutoCommit(true);
  external.setDefaultReadOnly(false);
  external.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
  external.setValidationQuery(null);// VALIDATION_SQL);
  external.setPoolPreparedStatements(true);

  return external;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:26,代码来源:RDB.java

示例13: initDataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@PostConstruct
public void initDataSource() throws Exception {
    // 读取jdbc.properties配置, 加载数据源
    Properties props = ResourceUtils.getResourceAsProperties("jdbc.properties");
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(JDBC_DRIVER_NAME);
    ds.setUrl(ensurePropValueNotNull(props.getProperty("db.url")));
    ds.setUsername(ensurePropValueNotNull(props.getProperty("db.user")));
    ds.setPassword(ensurePropValueNotNull(props.getProperty("db.password")));
    ds.setInitialSize(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.initialSize"))));
    ds.setMaxActive(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.maxActive"))));
    ds.setMaxIdle(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.maxIdle"))));
    ds.setMaxWait(Long.parseLong(ensurePropValueNotNull(props.getProperty("db.maxWait"))));
    ds.setPoolPreparedStatements(Boolean.parseBoolean(ensurePropValueNotNull(props
        .getProperty("db.poolPreparedStatements"))));

    this.jt = new JdbcTemplate();
    this.jt.setDataSource(ds);
    // 设置最大记录数,防止内存膨胀
    this.jt.setMaxRows(MAX_ROWS);
    // 设置JDBC执行超时时间
    this.jt.setQueryTimeout(QUERY_TIMEOUT);
}
 
开发者ID:lysu,项目名称:diamond,代码行数:24,代码来源:PersistService.java

示例14: createDataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private DataSource createDataSource(String url, String userName, String password, String driverClassName,
                                    DataMediaType dataMediaType, String encoding) {
    BasicDataSource dbcpDs = new BasicDataSource();

    dbcpDs.setRemoveAbandoned(true);
    dbcpDs.setLogAbandoned(true);
    dbcpDs.setTestOnBorrow(true);
    dbcpDs.setTestWhileIdle(true);

    // 动态的参数
    dbcpDs.setDriverClassName(driverClassName);
    dbcpDs.setUrl(url);
    dbcpDs.setUsername(userName);
    dbcpDs.setPassword(password);

    if (dataMediaType.isOracle()) {
        dbcpDs.addConnectionProperty("restrictGetTables", "true");
        dbcpDs.setValidationQuery("select 1 from dual");
    } else if (dataMediaType.isMysql()) {
        // open the batch mode for mysql since 5.1.8
        dbcpDs.addConnectionProperty("useServerPrepStmts", "true");
        dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
        if (StringUtils.isNotEmpty(encoding)) {
            dbcpDs.addConnectionProperty("characterEncoding", encoding);
        }
        dbcpDs.setValidationQuery("select 1");
    }

    return dbcpDs;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:31,代码来源:AbstractDbDialectTest.java

示例15: createDataSource

import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public DataSource createDataSource(String url, String driverClassName, String username, String password) {
	BasicDataSource ds = new SerializableBasicDataSource();
	ds.setUsername(username);
	ds.setPassword(password);
	ds.setUrl(url);
	ds.setDriverClassName(driverClassName);
	ds.setMaxActive(5);
	ds.setMaxIdle(2);
	return ds;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:11,代码来源:DbCommonServiceImpl.java


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