當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。