Java Code Examples for com.zaxxer.hikari.HikariDataSource#setJdbcUrl()
The following examples show how to use
com.zaxxer.hikari.HikariDataSource#setJdbcUrl() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastJdbc.java From litchi with Apache License 2.0 | 6 votes |
public void addJdbc(JSONObject config) { String dbType = config.getString("dbType"); String dbName = config.getString("dbName"); String host = config.getString("host"); String userName = config.getString("userName"); String password = config.getString("password"); // int initialSize = config.getInteger("initialSize"); // int maxActive = config.getInteger("maxActive"); // int maxIdle = config.getInteger("maxIdle"); // int minIdle = config.getInteger("minIdle"); HikariDataSource ds = new HikariDataSource(); String jdbc = "jdbc:mysql://%s/%s?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC"; ds.setJdbcUrl(String.format(jdbc, host, dbName)); ds.setUsername(userName); ds.setPassword(password); ds.addDataSourceProperty("cachePrepStmts", "true"); ds.addDataSourceProperty("prepStmtCacheSize", "500"); ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); QueryRunner queryRunner = new QueryRunner(ds); jdbcMaps.put(dbType, queryRunner); LOGGER.info("add jdbcId = {}", config.getString("id")); }
Example 2
Source File: BatchConfigurer.java From CogStack-Pipeline with Apache License 2.0 | 6 votes |
@Bean(destroyMethod = "close") @Qualifier("jobRepositoryDataSource") public DataSource jobRepositoryDataSource() { HikariDataSource mainDatasource = new HikariDataSource(); mainDatasource.setDriverClassName(repoDriver); mainDatasource.setJdbcUrl(repoJdbcPath); mainDatasource.setUsername(repoUserName); mainDatasource.setPassword(repoPassword); mainDatasource.setIdleTimeout(repoIdleTimeoutMs); mainDatasource.setMaxLifetime(repoMaxLifeTimeMs); if (repoPoolSize > 0) { mainDatasource.setMaximumPoolSize(repoPoolSize); } //mainDatasource.setAutoCommit(false); return mainDatasource; }
Example 3
Source File: Application.java From ShedLock with Apache License 2.0 | 6 votes |
@Bean public DataSource dataSource() { HikariDataSource datasource = new HikariDataSource(); datasource.setJdbcUrl("jdbc:hsqldb:mem:mymemdb"); datasource.setUsername("SA"); datasource.setPassword(""); new JdbcTemplate(datasource).execute("CREATE TABLE shedlock(\n" + " name VARCHAR(64), \n" + " lock_until TIMESTAMP(3) NULL, \n" + " locked_at TIMESTAMP(3) NULL, \n" + " locked_by VARCHAR(255), \n" + " PRIMARY KEY (name)\n" + ")"); return datasource; }
Example 4
Source File: DataSourceHandler.java From BungeeAdminTools with GNU General Public License v3.0 | 5 votes |
/** * Constructor used for MySQL * * @param host * @param port * @param database * @param username * @param password * @throws SQLException */ public DataSourceHandler(final String host, final String port, final String database, final String username, final String password) throws SQLException{ // Check database's informations and init connection this.host = Preconditions.checkNotNull(host); this.port = Preconditions.checkNotNull(port); this.database = Preconditions.checkNotNull(database); this.username = Preconditions.checkNotNull(username); this.password = Preconditions.checkNotNull(password); BAT.getInstance().getLogger().config("Initialization of HikariCP in progress ..."); BasicConfigurator.configure(new NullAppender()); ds = new HikariDataSource(); ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?useLegacyDatetimeCode=false&serverTimezone=" + TimeZone.getDefault().getID()); ds.setUsername(this.username); ds.setPassword(this.password); ds.addDataSourceProperty("cachePrepStmts", "true"); ds.setMaximumPoolSize(8); try { final Connection conn = ds.getConnection(); int intOffset = Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance().getTimeInMillis()) / 1000; String offset = String.format("%02d:%02d", Math.abs(intOffset / 3600), Math.abs((intOffset / 60) % 60)); offset = (intOffset >= 0 ? "+" : "-") + offset; conn.createStatement().executeQuery("SET time_zone='" + offset + "';"); conn.close(); BAT.getInstance().getLogger().config("BoneCP is loaded !"); } catch (final SQLException e) { BAT.getInstance().getLogger().severe("BAT encounters a problem during the initialization of the database connection." + " Please check your logins and database configuration."); if(e.getCause() instanceof CommunicationsException){ BAT.getInstance().getLogger().severe(e.getCause().getMessage()); } if(BAT.getInstance().getConfiguration().isDebugMode()){ BAT.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e); } throw e; } sqlite = false; }
Example 5
Source File: HikariPool.java From Java-11-Cookbook-Second-Edition with MIT License | 5 votes |
private static DataSource createDataSource1() { HikariDataSource ds = new HikariDataSource(); ds.setPoolName("cookpool"); ds.setDriverClassName("org.postgresql.Driver"); ds.setJdbcUrl("jdbc:postgresql://localhost/cookbook"); ds.setUsername( "cook"); //ds.setPassword("123Secret"); ds.setMaximumPoolSize(10); ds.setMinimumIdle(2); ds.addDataSourceProperty("cachePrepStmts", Boolean.TRUE); ds.addDataSourceProperty("prepStmtCacheSize", 256); ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048); ds.addDataSourceProperty("useServerPrepStmts", Boolean.TRUE); return ds; }
Example 6
Source File: BeetlConfig.java From spring-boot-demo with MIT License | 5 votes |
/** * Beetl需要显示的配置数据源,方可启动项目,大坑,切记! */ @Bean(name = "datasource") public DataSource getDataSource(Environment env){ HikariDataSource dataSource = new HikariDataSource(); dataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name")); dataSource.setJdbcUrl(env.getProperty("spring.datasource.url")); dataSource.setUsername(env.getProperty("spring.datasource.username")); dataSource.setPassword(env.getProperty("spring.datasource.password")); return dataSource; }
Example 7
Source File: DBConfiguration.java From Spring-5.0-Projects with MIT License | 5 votes |
@Bean public DataSource getDataSource() { HikariDataSource ds = new HikariDataSource(); ds.setJdbcUrl(jdbcUrl); ds.setUsername(username); ds.setPassword(password); ds.setDriverClassName(className); return ds; }
Example 8
Source File: IntegrationTestSupport.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
static JdbcTemplate jdbc(MySqlConnectionConfiguration configuration, @Nullable String timezone) { HikariDataSource source = new HikariDataSource(); source.setJdbcUrl(String.format("jdbc:mysql://%s:%d/%s", configuration.getDomain(), configuration.getPort(), configuration.getDatabase())); source.setUsername(configuration.getUser()); source.setPassword(Optional.ofNullable(configuration.getPassword()).map(Object::toString).orElse(null)); source.setMaximumPoolSize(1); source.setConnectionTimeout(Optional.ofNullable(configuration.getConnectTimeout()).map(Duration::toMillis).orElse(0L)); if (timezone != null) { source.addDataSourceProperty("serverTimezone", timezone); } return new JdbcTemplate(source); }
Example 9
Source File: TracingQueryExecutionListenerTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Bean public HikariDataSource test2() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl("jdbc:h2:mem:testdb-2-" + ThreadLocalRandom.current().nextInt()); dataSource.setPoolName("test2"); return dataSource; }
Example 10
Source File: HikariDataSourceConfiguration.java From sofa-tracer with Apache License 2.0 | 5 votes |
@Bean public DataSource hikariDataSource() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl(jdbcUrl); dataSource.setDriverClassName(driverClassName); dataSource.setUsername(username); dataSource.setPassword(password); return dataSource; }
Example 11
Source File: JdbcTestUtils.java From ShedLock with Apache License 2.0 | 5 votes |
public JdbcTestUtils(DbConfig dbConfig) { datasource = new HikariDataSource(); datasource.setJdbcUrl(dbConfig.getJdbcUrl()); datasource.setUsername(dbConfig.getUsername()); datasource.setPassword(dbConfig.getPassword()); jdbcTemplate = new JdbcTemplate(datasource); jdbcTemplate.execute(dbConfig.getCreateTableStatement()); }
Example 12
Source File: DataSourceConfig.java From spring-cloud-example with Apache License 2.0 | 5 votes |
@Bean public DataSource primaryDataSource() { HikariDataSource ds = new HikariDataSource(); ds.setMaximumPoolSize(100); ds.setMinimumIdle(30); ds.setDriverClassName("org.h2.Driver"); ds.setJdbcUrl("jdbc:h2:mem:test"); ds.setUsername("root"); ds.setPassword("root"); return ds; }
Example 13
Source File: DataSourceConfiguration.java From alf.io with GNU General Public License v3.0 | 5 votes |
@Bean @Profile({"!"+Initializer.PROFILE_INTEGRATION_TEST, "travis"}) public DataSource getDataSource(Environment env, PlatformProvider platform) { if(platform == PlatformProvider.CLOUD_FOUNDRY) { return new FakeCFDataSource(); } else { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl(platform.getUrl(env)); dataSource.setUsername(platform.getUsername(env)); dataSource.setPassword(platform.getPassword(env)); dataSource.setDriverClassName("org.postgresql.Driver"); dataSource.setMaximumPoolSize(platform.getMaxActive(env)); dataSource.setMinimumIdle(platform.getMinIdle(env)); dataSource.setConnectionTimeout(1000L); log.debug("Connection pool properties: max active {}, initial size {}", dataSource.getMaximumPoolSize(), dataSource.getMinimumIdle()); // check boolean isSuperAdmin = Boolean.TRUE.equals(new NamedParameterJdbcTemplate(dataSource) .queryForObject("select usesuper from pg_user where usename = CURRENT_USER", new EmptySqlParameterSource(), Boolean.class)); if (isSuperAdmin) { log.warn("You're accessing the database using a superuser. This is highly discouraged since it will disable the row security policy checks."); } // return dataSource; } }
Example 14
Source File: BeetlConfig.java From spring-boot-demo with MIT License | 5 votes |
/** * Beetl需要显示的配置数据源,方可启动项目,大坑,切记! */ @Bean(name = "datasource") public DataSource getDataSource(Environment env){ HikariDataSource dataSource = new HikariDataSource(); dataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name")); dataSource.setJdbcUrl(env.getProperty("spring.datasource.url")); dataSource.setUsername(env.getProperty("spring.datasource.username")); dataSource.setPassword(env.getProperty("spring.datasource.password")); return dataSource; }
Example 15
Source File: TestConfiguration.java From alf.io with GNU General Public License v3.0 | 5 votes |
@Bean @Profile("!travis") public DataSource getDataSource(EmbeddedPostgres postgres) { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl(postgres.getJdbcUrl(POSTGRES_USERNAME, POSTGRES_DB)); dataSource.setUsername(POSTGRES_USERNAME); dataSource.setPassword(POSTGRES_PASSWORD); dataSource.setDriverClassName("org.postgresql.Driver"); dataSource.setMaximumPoolSize(5); return dataSource; }
Example 16
Source File: MysqlDataSourceBuilder.java From micro-server with Apache License 2.0 | 5 votes |
private DataSource getDataSource() { HikariDataSource ds = new HikariDataSource(); ds.setDriverClassName(env.getDriverClassName()); ds.setJdbcUrl(env.getUrl()); ds.setUsername(env.getUsername()); ds.setPassword(env.getPassword()); ds.setMaximumPoolSize(env.getMaxPoolSize()); return ds; }
Example 17
Source File: DataSourceFactory.java From shardingsphere with Apache License 2.0 | 5 votes |
private DataSource newInstanceDataSourceByJDBC(final JDBCDataSourceConfiguration dataSourceConfiguration) { HikariDataSource result = new HikariDataSource(); result.setJdbcUrl(dataSourceConfiguration.getJdbcUrl()); result.setUsername(dataSourceConfiguration.getUsername()); result.setPassword(dataSourceConfiguration.getPassword()); return result; }
Example 18
Source File: EnodeTestDataSourceConfig.java From enode with MIT License | 5 votes |
@Bean("enodeTiDBDataSource") @ConditionalOnProperty(prefix = "spring.enode", name = "eventstore", havingValue = "tidb") public HikariDataSource tidbDataSource() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:4000/enode?"); dataSource.setUsername("root"); dataSource.setPassword(""); dataSource.setDriverClassName(com.mysql.cj.jdbc.Driver.class.getName()); return dataSource; }
Example 19
Source File: PostgresDAOTestUtil.java From conductor with Apache License 2.0 | 5 votes |
private HikariDataSource getDataSource(Configuration config) { HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl(config.getProperty("jdbc.url", JDBC_URL_PREFIX + "conductor")); dataSource.setUsername(config.getProperty("jdbc.username", "postgres")); dataSource.setPassword(config.getProperty("jdbc.password", "postgres")); dataSource.setAutoCommit(false); // Prevent DB from getting exhausted during rapid testing dataSource.setMaximumPoolSize(8); flywayMigrate(dataSource); return dataSource; }
Example 20
Source File: ConnectionProviderPooled.java From rxjava-jdbc with Apache License 2.0 | 3 votes |
/** * Returns a new pooled data source based on jdbc url. * * @param url * jdbc url * @param username * login username * @param password * login password * @param minPoolSize * minimum database connection pool size * @param maxPoolSize * maximum database connection pool size * @param connectionTimeoutMs * @return */ private static HikariDataSource createPool(String url, String username, String password, int minPoolSize, int maxPoolSize, long connectionTimeoutMs) { HikariDataSource ds = new HikariDataSource(); ds.setJdbcUrl(url); ds.setUsername(username); ds.setPassword(password); ds.setMinimumIdle(minPoolSize); ds.setMaximumPoolSize(maxPoolSize); ds.setConnectionTimeout(connectionTimeoutMs); return ds; }