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


Java HikariConfig.setJdbcUrl方法代码示例

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


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

示例1: enableDatabaseMySQLTest

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
    try {
        final DB database = DB.newEmbeddedDB(3306);
        database.start();
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
            try (Statement statement = conn.createStatement()) {
                statement.executeUpdate("CREATE DATABASE db");
            }
        }

        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
        database.stop();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assertions.fail(ex);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:27,代码来源:DatabaseTest.java

示例2: enableDatabaseSQLiteTest

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseSQLiteTest() {
    try {
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:18,代码来源:DatabaseIT.java

示例3: getDataSourceFromConfig

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public static HikariDataSource getDataSourceFromConfig(
    Config conf
    , MetricRegistry metricRegistry
    , HealthCheckRegistry healthCheckRegistry) {

    HikariConfig jdbcConfig = new HikariConfig();
    jdbcConfig.setPoolName(conf.getString("poolName"));
    jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize"));
    jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle"));
    jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl"));
    jdbcConfig.setUsername(conf.getString("username"));
    jdbcConfig.setPassword(conf.getString("password"));

    jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit"));
    jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts"));

    // Add HealthCheck
    jdbcConfig.setHealthCheckRegistry(healthCheckRegistry);

    // Add Metrics
    jdbcConfig.setMetricRegistry(metricRegistry);
    return new HikariDataSource(jdbcConfig);
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:26,代码来源:ConnectionPool.java

示例4: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
public DataSource dataSource() {
    HikariConfig dataSourceConfig = new HikariConfig();
    dataSourceConfig.setDriverClassName(environment.getRequiredProperty("spring.datasource.driver-class-name"));
    dataSourceConfig.setJdbcUrl(environment.getRequiredProperty("spring.datasource.url"));
    dataSourceConfig.setUsername(environment.getRequiredProperty("spring.datasource.username"));
    dataSourceConfig.setPassword(environment.getRequiredProperty("spring.datasource.password"));
    dataSourceConfig.setMaximumPoolSize(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maximumPoolSize")));
    dataSourceConfig.setMinimumIdle(Integer.parseInt(environment.getRequiredProperty("spring.datasource.minimumIdle")));
    dataSourceConfig.setMaxLifetime(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maxLifetime")));
    dataSourceConfig.setConnectionTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.connectionTimeout")));
    dataSourceConfig.setIdleTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.idleTimeout")));
    dataSourceConfig.addDataSourceProperty("poolName", environment.getRequiredProperty("spring.datasource.poolName"));
    dataSourceConfig.addDataSourceProperty("cachePrepStmts", "true");
    dataSourceConfig.addDataSourceProperty("prepStmtCacheSize", "250");
    dataSourceConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    return new HikariDataSource(dataSourceConfig);
}
 
开发者ID:RizkiMufrizal,项目名称:Spring-OAuth2-Custom,代码行数:19,代码来源:DataSourceConfiguration.java

示例5: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close") // Should happen anyway, but worth calling out
@Primary
public HikariDataSource dataSource() throws ParserConfigurationException, IOException, SAXException, ParseException {
    ApplicationConfig appConfig = applicationConfig();

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl("jdbc:" + appConfig.getDbUrl() + "/" + appConfig.getDbName());
    hikariConfig.setUsername(appConfig.getDbUser());
    hikariConfig.setPassword(appConfig.getDbPassword());
    hikariConfig.setMaximumPoolSize(appConfig.getThreadLimit());
    hikariConfig.setInitializationFailTimeout(30000);
    if(appConfig.isDbIgnoreSSLWarn()) {
        hikariConfig.addDataSourceProperty("useSSL", false);
    }

    return new HikariDataSource(hikariConfig);
}
 
开发者ID:XIVStats,项目名称:XIVStats-Gatherer-Java,代码行数:18,代码来源:SpringConfiguration.java

示例6: getConnection

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public static DataSource getConnection() {
    if (ds == null) {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:mysql://localhost:3306/library");
        config.setUsername("root");
        config.setPassword("sds");
        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
        ds = new HikariDataSource(config);
        return ds;


    } else {

        return ds;
    }

}
 
开发者ID:skyrocknroll,项目名称:jooq-test,代码行数:20,代码来源:DbConnectionPool.java

示例7: createDataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private static DataSource createDataSource(String[] args) {
    final HikariConfig config = new HikariConfig();

    final String dbName = args[0];
    final String username = args[1];
    final String password = args[2];

    log().info("Start `DataSource` creation. The following parameters will be used:");
    final String dbUrl = format(DB_URL_FORMAT, getDbUrlPrefix(), dbName);
    config.setJdbcUrl(dbUrl);
    log().info("JDBC URL: {}", dbUrl);

    config.setUsername(username);
    log().info("Username: {}", username);

    config.setPassword(password);
    log().info("Password: {}", password);

    final DataSource dataSource = new HikariDataSource(config);
    return dataSource;
}
 
开发者ID:SpineEventEngine,项目名称:todo-list,代码行数:22,代码来源:LocalMySqlServer.java

示例8: setup

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
protected void setup(Jecon jecon, HikariConfig hikariConfig) {
	this.jecon = jecon;
	if (config == null) {
		config = jecon.getConfigStruct();
	}
	this.prefix = config.getDbConfig().prefix;

	hikariConfig.setJdbcUrl(config.getDbConfig().url);
	hikariConfig.setInitializationFailFast(true);
	hikariConfig.setAutoCommit(true);
	hikariConfig.setConnectionInitSql("/* Jecon */SELECT 1");

	if (config.getDbConfig().poolSize > 0) {
		hikariConfig.setMaximumPoolSize(config.getDbConfig().poolSize);
	}
	if (config.getDbConfig().timeout > 0) {
		hikariConfig.setIdleTimeout(config.getDbConfig().timeout);
	}

	hikariConfig.setDataSourceProperties(config.getDbConfig().propaties);

	// HikariDataSourceをインスタンス化
	this.hikariDc = new HikariDataSource(hikariConfig);

	this.createTable();
}
 
开发者ID:HimaJyun,项目名称:Jecon,代码行数:27,代码来源:Database.java

示例9: initConnection

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private void initConnection() throws Exception {
	HikariConfig config = new HikariConfig();
	config.setPoolName("Parties");
	config.setJdbcUrl(Variables.storage_settings_mysql_url);
	config.setUsername(Variables.storage_settings_mysql_username);
	config.setPassword(Variables.storage_settings_mysql_password);
	config.setMaximumPoolSize(Variables.storage_settings_mysql_poolsize);
	config.setMinimumIdle(Variables.storage_settings_mysql_poolsize);
	config.setMaxLifetime(Variables.storage_settings_mysql_connlifetime);
	config.setIdleTimeout(Variables.storage_settings_mysql_conntimeout);
	
	// Properties: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
	config.addDataSourceProperty("cachePreStmts", "true"); // Enable Prepared Statement caching
	config.addDataSourceProperty("prepStmtCacheSize", "25"); // How many PS cache, default: 25
	config.addDataSourceProperty("useServerPrepStmts", "true"); // If supported use PS server-side
	config.addDataSourceProperty("useLocalSessionState", "true"); // Enable setAutoCommit
	config.addDataSourceProperty("useLocalTransactionState", "true"); // Enable commit/rollbacks
	
	hikariDataSource = new HikariDataSource(config);
}
 
开发者ID:AlessioDP,项目名称:Parties,代码行数:21,代码来源:MySQLData.java

示例10: testConnection

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public void testConnection(String url, String username, String password) throws Exception {

    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    config.setJdbcUrl(url);
    config.setUsername(username);
    config.setPassword(password);
    config.setPoolName("easyrecPool");
    config.addDataSourceProperty("url", url);
    HikariDataSource ds = new HikariDataSource(config);

    setDataSource(ds);
    sqlScriptService.setDataSource(ds);
    
    boolean tablesOk = false;

    DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
        public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
            ResultSet rs = dbmd.getTables(null, null, "operator", null);
            return rs.next();
        }
    };

    tablesOk = (Boolean) JdbcUtils.extractDatabaseMetaData(ds, callback);
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:27,代码来源:LoaderDAOMysqlImpl.java

示例11: startup

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
/**
 *
 */
@Inject
public void startup() {
    if (ds != null && !ds.isClosed()) {
        return;
    }

    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(configuration.dbUrl());
    config.setUsername(configuration.dbUsername());
    config.setPassword(configuration.dbPassword());
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

    ds = new HikariDataSource(config);

    initializeDatabase();
}
 
开发者ID:jVoid,项目名称:jVoid,代码行数:22,代码来源:MetadataDatabase.java

示例12: createLocalMariaDb

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private Database createLocalMariaDb() {
	HikariConfig config = new HikariConfig();
	config.setJdbcUrl(
			"jdbc:mariadb://localhost:3406/test?autoReconnect=true&?useUnicode=yes&characterEncoding=UTF-8");
	config.setUsername("test");
	config.setPassword("test");
	config.setAutoCommit(false);
	config.setDriverClassName("org.mariadb.jdbc.Driver");
	Database mariaDb = new Database(new HikariDataSource(config));
	return mariaDb;
}
 
开发者ID:jaregu,项目名称:queries,代码行数:12,代码来源:SampleQueries.java

示例13: billingDataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
public DataSource billingDataSource(
        @Value("${ru.mipt.java2016.homework.g597.zakharkin.task4.jdbcUrl}") String jdbcUrl,
        @Value("${ru.mipt.java2016.homework.g597.zakharkin.task4.username:}") String username,
        @Value("${ru.mipt.java2016.homework.g597.zakharkin.task4.password:}") String password
) {
    HikariConfig config = new HikariConfig();
    config.setDriverClassName(org.h2.Driver.class.getName());
    config.setJdbcUrl(jdbcUrl);
    config.setUsername(username);
    config.setPassword(password);
    return new HikariDataSource(config);
}
 
开发者ID:izaharkin,项目名称:JavaRestCalculator,代码行数:14,代码来源:BillingDatabaseConfiguration.java

示例14: getDataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
@Primary
public DataSource getDataSource() {
    HikariConfig config = new HikariConfig();
    config.setDriverClassName("com.mysql.jdbc.Driver");
    config.setJdbcUrl("jdbc:mysql://localhost:3306/test");
    config.setUsername("root");
    config.setPassword("root");
    config.setMaximumPoolSize(500);
    config.setMinimumIdle(10);
    return new HikariDataSource(config);
}
 
开发者ID:SkywalkingTest,项目名称:Agent-Benchmarks,代码行数:13,代码来源:DataSourceConfiguration.java

示例15: get

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public DataSource get() {
    HikariConfig config = new HikariConfig();

    config.setJdbcUrl("jdbc:mysql://localhost:3306/db_example");
    config.setUsername("tully");
    config.setPassword("tully");

    config.setMaximumPoolSize(10);
    config.setAutoCommit(false);
    config.setRegisterMbeans(true);

    return new HikariDataSource(config);
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_04,代码行数:15,代码来源:HikariCPDataSourceFactory.java


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