本文整理汇总了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);
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}