Java Code Examples for com.zaxxer.hikari.HikariConfig#setJdbcUrl()

The following examples show how to use com.zaxxer.hikari.HikariConfig#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: ConnectionPool.java    From StubbornJava with MIT License 6 votes vote down vote up
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);
}
 
Example 2
Source File: SagaPersistenceLoader.java    From opensharding-spi-impl with Apache License 2.0 6 votes vote down vote up
private static DataSource initDataSource(final SagaPersistenceConfiguration persistenceConfiguration) {
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(persistenceConfiguration.getUrl());
    config.setUsername(persistenceConfiguration.getUsername());
    config.setPassword(persistenceConfiguration.getPassword());
    config.setConnectionTimeout(persistenceConfiguration.getConnectionTimeoutMilliseconds());
    config.setIdleTimeout(persistenceConfiguration.getIdleTimeoutMilliseconds());
    config.setMaxLifetime(persistenceConfiguration.getMaxLifetimeMilliseconds());
    config.setMaximumPoolSize(persistenceConfiguration.getMaxPoolSize());
    config.setMinimumIdle(persistenceConfiguration.getMinPoolSize());
    config.addDataSourceProperty("useServerPrepStmts", Boolean.TRUE.toString());
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", 250);
    config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
    config.addDataSourceProperty("useLocalSessionState", Boolean.TRUE.toString());
    config.addDataSourceProperty("rewriteBatchedStatements", Boolean.TRUE.toString());
    config.addDataSourceProperty("cacheResultSetMetadata", Boolean.TRUE.toString());
    config.addDataSourceProperty("cacheServerConfiguration", Boolean.TRUE.toString());
    config.addDataSourceProperty("elideSetAutoCommits", Boolean.TRUE.toString());
    config.addDataSourceProperty("maintainTimeStats", Boolean.FALSE.toString());
    config.addDataSourceProperty("netTimeoutForStreamingResults", 0);
    return new HikariDataSource(config);
}
 
Example 3
Source File: HikariCPPlugin.java    From jfinal-api-scaffold with MIT License 6 votes vote down vote up
@Override
    public boolean start() {
        HikariConfig config = new HikariConfig();
        config.setMaximumPoolSize(maxPoolSize);
//        config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
        config.setDriverClassName(driverClass);
        config.setJdbcUrl(jdbcUrl);
        config.setUsername(user);
        config.setPassword(password);
        
        //防止中文乱码
        config.addDataSourceProperty("useUnicode", "true");
        config.addDataSourceProperty("characterEncoding", "utf8");
        
        config.setConnectionTestQuery("SELECT 1");

        this.dataSource = new HikariDataSource(config);
        
        return true;
    }
 
Example 4
Source File: DITestingConfiguration.java    From waltz with Apache License 2.0 6 votes vote down vote up
@Bean
public DataSource dataSource() {
    HikariConfig dsConfig = new HikariConfig();
    postgreSQLContainer.start();
    dsConfig.setJdbcUrl(format("jdbc:postgresql://%s:%s/%s",
            postgreSQLContainer.getContainerIpAddress(),
            postgreSQLContainer.getMappedPort(PostgreSQLContainer.POSTGRESQL_PORT),
            postgreSQLContainer.getDatabaseName()));
    dsConfig.setUsername(postgreSQLContainer.getUsername());
    dsConfig.setPassword(postgreSQLContainer.getPassword());
    dsConfig.setSchema("test");
    dsConfig.setDriverClassName("org.postgresql.Driver");
    dsConfig.setMaximumPoolSize(5);
    dsConfig.setMinimumIdle(2);
    return new HikariDataSource(dsConfig);
}
 
Example 5
Source File: MySQLDataSourceProvider.java    From conductor with Apache License 2.0 6 votes vote down vote up
private HikariConfig createConfiguration(){
    HikariConfig cfg = new HikariConfig();
    cfg.setJdbcUrl(configuration.getJdbcUrl());
    cfg.setUsername(configuration.getJdbcUserName());
    cfg.setPassword(configuration.getJdbcPassword());
    cfg.setAutoCommit(false);
    cfg.setMaximumPoolSize(configuration.getConnectionPoolMaxSize());
    cfg.setMinimumIdle(configuration.getConnectionPoolMinIdle());
    cfg.setMaxLifetime(configuration.getConnectionMaxLifetime());
    cfg.setIdleTimeout(configuration.getConnectionIdleTimeout());
    cfg.setConnectionTimeout(configuration.getConnectionTimeout());
    cfg.setTransactionIsolation(configuration.getTransactionIsolationLevel());
    cfg.setAutoCommit(configuration.isAutoCommit());

    ThreadFactory tf = new ThreadFactoryBuilder()
            .setDaemon(true)
            .setNameFormat("hikari-mysql-%d")
            .build();

    cfg.setThreadFactory(tf);
    return cfg;
}
 
Example 6
Source File: Main.java    From fahrschein with Apache License 2.0 6 votes vote down vote up
private static void persistentListen(ObjectMapper objectMapper, Listener<SalesOrderPlaced> listener) throws IOException {
    final HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(JDBC_URL);
    hikariConfig.setUsername(JDBC_USERNAME);
    hikariConfig.setPassword(JDBC_PASSWORD);

    final DataSource dataSource = new HikariDataSource(hikariConfig);

    final JdbcCursorManager cursorManager = new JdbcCursorManager(dataSource, "fahrschein-demo");

    final NakadiClient nakadiClient = NakadiClient.builder(NAKADI_URI)
            .withAccessTokenProvider(new ZignAccessTokenProvider())
            .withCursorManager(cursorManager)
            .build();

    final List<Partition> partitions = nakadiClient.getPartitions(SALES_ORDER_SERVICE_ORDER_PLACED);

    nakadiClient.stream(SALES_ORDER_SERVICE_ORDER_PLACED)
            .readFromBegin(partitions)
            .withObjectMapper(objectMapper)
            .listen(SalesOrderPlaced.class, listener);
}
 
Example 7
Source File: DatabaseConfig.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean
public DataSource dataSource() throws SQLException {
    DatabaseUtil.createSchemaIfNeeded("postgresql", databaseAddress, dbName, dbUser, dbPassword, dbSchemaName);
    HikariConfig config = new HikariConfig();
    if (ssl && Files.exists(Paths.get(certFile))) {
        config.addDataSourceProperty("ssl", "true");
        config.addDataSourceProperty("sslfactory", "org.postgresql.ssl.SingleCertValidatingFactory");
        config.addDataSourceProperty("sslfactoryarg", "file://" + certFile);
    }
    if (nodeConfig.isNodeIdSpecified()) {
        config.addDataSourceProperty("ApplicationName", nodeConfig.getId());
    }
    config.setDriverClassName("io.opentracing.contrib.jdbc.TracingDriver");
    config.setJdbcUrl(String.format("jdbc:tracing:postgresql://%s/%s?currentSchema=%s", databaseAddress, dbName, dbSchemaName));
    config.setUsername(dbUser);
    config.setPassword(dbPassword);
    config.setMaximumPoolSize(poolSize);
    config.setMinimumIdle(minimumIdle);
    config.setConnectionTimeout(SECONDS.toMillis(connectionTimeout));
    config.setIdleTimeout(MINUTES.toMillis(idleTimeout));
    return new HikariDataSource(config);
}
 
Example 8
Source File: ConnectionPool.java    From StubbornJava with MIT License 6 votes vote down vote up
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);
}
 
Example 9
Source File: ConnectionManager.java    From pxf with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new datasource instance based on parameters contained in PoolDescriptor.
 * @param poolDescriptor descriptor containing pool parameters
 * @return instance of HikariDataSource
 */
HikariDataSource createDataSource(PoolDescriptor poolDescriptor) {

    // initialize Hikari config with provided properties
    Properties configProperties = poolDescriptor.getPoolConfig() != null ? poolDescriptor.getPoolConfig() : new Properties();
    HikariConfig config = new HikariConfig(configProperties);

    // overwrite jdbcUrl / userName / password with the values provided explicitly
    config.setJdbcUrl(poolDescriptor.getJdbcUrl());
    config.setUsername(poolDescriptor.getUser());
    config.setPassword(poolDescriptor.getPassword());

    // set connection properties as datasource properties
    if (poolDescriptor.getConnectionConfig() != null) {
        poolDescriptor.getConnectionConfig().forEach((key, value) ->
                config.addDataSourceProperty((String) key, value));
    }

    HikariDataSource result = new HikariDataSource(config);
    LOG.debug("Created new instance of HikariDataSource: {}", result);

    return result;
}
 
Example 10
Source File: JooqJobActivityConnectorComponent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public JooqContext getJooqContext(JooqConfiguration jooqConfiguration, EmbeddedPostgresService embeddedPostgresService) {
    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setAutoCommit(true);

    // Connection management
    hikariConfig.setConnectionTimeout(10000);
    hikariConfig.setMaximumPoolSize(10);
    hikariConfig.setLeakDetectionThreshold(3000);

    if (jooqConfiguration.isInMemoryDb()) {
        hikariConfig.setDataSource(embeddedPostgresService.getDataSource());
    } else {
        hikariConfig.addDataSourceProperty(PGProperty.SSL.getName(), "true");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_MODE.getName(), "verify-ca");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_FACTORY.getName(), RDSSSLSocketFactory.class.getName());
        hikariConfig.setJdbcUrl(jooqConfiguration.getDatabaseUrl());
    }

    return new JooqContext(jooqConfiguration, new HikariDataSource(hikariConfig), embeddedPostgresService);
}
 
Example 11
Source File: MysqlSchemaRepositoryIT.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void connect() throws Exception {
  HikariConfig hikariConfig = new HikariConfig();
  hikariConfig.setJdbcUrl(mysql.getJdbcUrl());
  hikariConfig.setUsername(mysql.getUsername());
  hikariConfig.setPassword(mysql.getPassword());
  hikariConfig.addDataSourceProperty("useSSL", false);
  hikariConfig.setAutoCommit(false);
  ds = new HikariDataSource(hikariConfig);
  Utils.runInitScript("schema.sql", ds);
}
 
Example 12
Source File: Storage.java    From Kepler with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Storage(String host, int port, String username, String password, String db) {
    try {
        HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.mariadb.jdbc.Driver");
        config.setJdbcUrl("jdbc:mariadb://" + host + ":" + port + "/" + db);
        config.setUsername(username);
        config.setPassword(password);

        config.setPoolName("processing");

        // No martinmine/Leon/other Habbotards, you don't know better.
        // Read up on this first, before commenting dumb shit
        // https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing
        // availableProcessors() already returns thread count on hyper-threaded processors
        // Thus we don't need the * 2 described there
        config.setMaximumPoolSize(Runtime.getRuntime().availableProcessors() + 1);
        config.setMinimumIdle(1);

        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
        config.addDataSourceProperty("characterEncoding", "utf8");
        config.addDataSourceProperty("useUnicode", "true");
        config.addDataSourceProperty("useSSL", "false");
        config.addDataSourceProperty("serverTimezone", "UTC");
        config.addDataSourceProperty("sessionVariables", "sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");

        this.ds = new HikariDataSource(config);
        this.isConnected = true;

    } catch (Exception ex) {
        Storage.logError(ex);
    }
}
 
Example 13
Source File: MySQL.java    From MySQL with MIT License 5 votes vote down vote up
/**
 * Creates a new MySQL instance for a specific database
 *
 * @param hostname | Name of the host
 * @param port     | Port number
 * @param database | Database name
 * @param username | Username
 * @param password | Password
 * @param params   | Extra parameters
 */
public MySQL(String hostname, String port, String database, String username, String password, String params) {

    // Build URL of database
    StringBuilder urlBuild = new StringBuilder();
    urlBuild.append("jdbc:mysql://");
    urlBuild.append(hostname);
    urlBuild.append(":");
    urlBuild.append(port);
    urlBuild.append("/");
    urlBuild.append(database);

    // Params to db url
    if (!params.isEmpty()) {

        if (!params.startsWith("?")) urlBuild.append("?");

        urlBuild.append(params);
    }

    // Begin configuration of Hikari DataSource
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(urlBuild.toString());
    config.setUsername(username);
    config.setPassword(password);

    // See: https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("useServerPrepStmts", "true");
    config.addDataSourceProperty("useLocalSessionState", "true");
    config.addDataSourceProperty("rewriteBatchedStatements", "true");
    config.addDataSourceProperty("cacheResultSetMetadata", "true");
    config.addDataSourceProperty("cacheServerConfiguration", "true");
    config.addDataSourceProperty("elideSetAutoCommits", "true");
    config.addDataSourceProperty("maintainTimeStats", "false");

    dataSource = new HikariDataSource(config);
}
 
Example 14
Source File: AbstractJDBCDriverTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
private HikariDataSource getDataSource(String jdbcUrl, int poolSize) {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(jdbcUrl);
    hikariConfig.setConnectionTestQuery("SELECT 1");
    hikariConfig.setMinimumIdle(1);
    hikariConfig.setMaximumPoolSize(poolSize);

    return new HikariDataSource(hikariConfig);
}
 
Example 15
Source File: HikariDataSourceFactory.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource createDataSource(DataSourceConfig config) {

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(config.getUrl());
    hikariConfig.setUsername(config.getUser());
    hikariConfig.setPassword(config.getPassword());
    hikariConfig.addDataSourceProperty("cachePrepStmts", config.isCachePrepStmts());
    hikariConfig.addDataSourceProperty("prepStmtCacheSize", config.getPrepStmtCacheSize());
    hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", config.getPrepStmtCacheSqlLimit());
    hikariConfig.setDriverClassName(config.getDriverClassName());
    hikariConfig.setPoolName(config.getPoolName());
    hikariConfig.setMaximumPoolSize(config.getMaximumPoolSize());

    if (config.getMaxLifetime() != null) {
        hikariConfig.setMaxLifetime(config.getMaxLifetime());
    }
    if (config.getIdleTimeout() != null) {
        hikariConfig.setIdleTimeout(config.getIdleTimeout());
    }

    if (config.getMinimumIdle() != null) {
        hikariConfig.setMinimumIdle(config.getMinimumIdle());
    }

    if (config.getConnectionInitSql() != null) {
        hikariConfig.setConnectionInitSql(config.getConnectionInitSql());
    }


    HikariDataSource dataSource = new HikariDataSource(hikariConfig);

    if (Jboot.getMetric() != null) {
        dataSource.setMetricRegistry(Jboot.getMetric());
    }

    return dataSource;
}
 
Example 16
Source File: DefaultDataSourceFactory.java    From qmq with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource createDataSource(DynamicConfig config) {
	final HikariConfig cpConfig = new HikariConfig();
	cpConfig.setDriverClassName(config.getString("jdbc.driverClassName", "com.mysql.jdbc.Driver"));
	cpConfig.setJdbcUrl(config.getString("jdbc.url"));
	cpConfig.setUsername(config.getString("jdbc.username"));
	cpConfig.setPassword(config.getString("jdbc.password"));
	cpConfig.setMaximumPoolSize(config.getInt("pool.size.max", 10));

	return new HikariDataSource(cpConfig);
}
 
Example 17
Source File: ConnectionPoolingIT.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
private HikariDataSource initHikariDataSource() throws SQLException
{
  HikariConfig config = new HikariConfig();
  config.setDriverClassName(BaseJDBCTest.DRIVER_CLASS);
  config.setDataSourceProperties(setUpConnectionProperty());
  config.setJdbcUrl(connectStr);
  return new HikariDataSource(config);
}
 
Example 18
Source File: SQLite.java    From ShopChest with MIT License 5 votes vote down vote up
@Override
HikariDataSource getDataSource() {
    try {
        // Initialize driver class so HikariCP can find it
        Class.forName("org.sqlite.JDBC");
    } catch (ClassNotFoundException e) {
        plugin.getLogger().severe("Failed to initialize SQLite driver");
        plugin.debug("Failed to initialize SQLite driver");
        plugin.debug(e);
        return null;
    }

    File folder = plugin.getDataFolder();
    File dbFile = new File(folder, "shops.db");

    if (!dbFile.exists()) {
        try {
            dbFile.createNewFile();
        } catch (IOException ex) {
            plugin.getLogger().severe("Failed to create database file");
            plugin.debug("Failed to create database file");
            plugin.debug(ex);
            return null;
        }
    }
    
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(String.format("jdbc:sqlite:" + dbFile));
    config.setConnectionTestQuery("SELECT 1");

    return new HikariDataSource(config);
}
 
Example 19
Source File: JDBCDriverWithPoolTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
private static HikariDataSource getHikariDataSource() {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(URL + ";TEST=HIKARI"); // append a dummy URL element to ensure different DB per test
    hikariConfig.setConnectionTestQuery("SELECT 1");
    hikariConfig.setMinimumIdle(3);
    hikariConfig.setMaximumPoolSize(10);

    return new HikariDataSource(hikariConfig);
}
 
Example 20
Source File: ConnectionPoolContextListener.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@SuppressFBWarnings(
    value = "USBR_UNNECESSARY_STORE_BEFORE_RETURN",
    justification = "Necessary for sample region tag.")
private DataSource createConnectionPool() {
  // [START cloud_sql_mysql_servlet_create]
  // The configuration object specifies behaviors for the connection pool.
  HikariConfig config = new HikariConfig();

  // Configure which instance and what database user to connect with.
  config.setJdbcUrl(String.format("jdbc:mysql:///%s", DB_NAME));
  config.setUsername(DB_USER); // e.g. "root", "postgres"
  config.setPassword(DB_PASS); // e.g. "my-password"

  // For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections.
  // See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
  config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.mysql.SocketFactory");
  config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME);

  // ... Specify additional connection properties here.
  // [START_EXCLUDE]

  // [START cloud_sql_mysql_servlet_limit]
  // maximumPoolSize limits the total number of concurrent connections this pool will keep. Ideal
  // values for this setting are highly variable on app design, infrastructure, and database.
  config.setMaximumPoolSize(5);
  // minimumIdle is the minimum number of idle connections Hikari maintains in the pool.
  // Additional connections will be established to meet this value unless the pool is full.
  config.setMinimumIdle(5);
  // [END cloud_sql_mysql_servlet_limit]

  // [START cloud_sql_mysql_servlet_timeout]
  // setConnectionTimeout is the maximum number of milliseconds to wait for a connection checkout.
  // Any attempt to retrieve a connection from this pool that exceeds the set limit will throw an
  // SQLException.
  config.setConnectionTimeout(10000); // 10 seconds
  // idleTimeout is the maximum amount of time a connection can sit in the pool. Connections that
  // sit idle for this many milliseconds are retried if minimumIdle is exceeded.
  config.setIdleTimeout(600000); // 10 minutes
  // [END cloud_sql_mysql_servlet_timeout]

  // [START cloud_sql_mysql_servlet_backoff]
  // Hikari automatically delays between failed connection attempts, eventually reaching a
  // maximum delay of `connectionTimeout / 2` between attempts.
  // [END cloud_sql_mysql_servlet_backoff]

  // [START cloud_sql_mysql_servlet_lifetime]
  // maxLifetime is the maximum possible lifetime of a connection in the pool. Connections that
  // live longer than this many milliseconds will be closed and reestablished between uses. This
  // value should be several minutes shorter than the database's timeout value to avoid unexpected
  // terminations.
  config.setMaxLifetime(1800000); // 30 minutes
  // [END cloud_sql_mysql_servlet_lifetime]

  // [END_EXCLUDE]

  // Initialize the connection pool using the configuration object.
  DataSource pool = new HikariDataSource(config);
  // [END cloud_sql_mysql_servlet_create]
  return pool;
}