| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fead834 commit b594c48
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,12 @@ private DataSource createConnectionPool() { | |||
| 50 | 50 | // The configuration object specifies behaviors for the connection pool. | |
| 51 | 51 | HikariConfig config = new HikariConfig(); | |
| 52 | 52 | ||
| 53 | + // The following URL is equivalent to setting the config options below: | ||
| 54 | + // jdbc:postgresql:///<DB_NAME>?cloudSqlInstance=<CLOUD_SQL_CONNECTION_NAME>& | ||
| 55 | + // socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=<DB_USER>&password=<DB_PASS> | ||
| 56 | + // See the link below for more info on building a JDBC URL for the Cloud SQL JDBC Socket Factory | ||
| 57 | + // https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory#creating-the-jdbc-url | ||
| 58 | + | ||
| 53 | 59 | // Configure which instance and what database user to connect with. | |
| 54 | 60 | config.setJdbcUrl(String.format("jdbc:mysql:///%s", DB_NAME)); | |
| 55 | 61 | config.setUsername(DB_USER); // e.g. "root", "postgres" | |
@@ -110,7 +116,7 @@ private void createTable(DataSource pool) throws SQLException { | |||
| 110 | 116 | "CREATE TABLE IF NOT EXISTS votes ( " | |
| 111 | 117 | + "vote_id SERIAL NOT NULL, time_cast timestamp NOT NULL, candidate CHAR(6) NOT NULL," | |
| 112 | 118 | + " PRIMARY KEY (vote_id) );"; | |
| 113 | - try (PreparedStatement createTableStatement = conn.prepareStatement(stmt); ) { | ||
| 119 | + try (PreparedStatement createTableStatement = conn.prepareStatement(stmt);) { | ||
| 114 | 120 | createTableStatement.execute(); | |
| 115 | 121 | } | |
| 116 | 122 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,12 @@ private DataSource createConnectionPool() { | |||
| 50 | 50 | // The configuration object specifies behaviors for the connection pool. | |
| 51 | 51 | HikariConfig config = new HikariConfig(); | |
| 52 | 52 | ||
| 53 | + // The following URL is equivalent to setting the config options below: | ||
| 54 | + // jdbc:postgresql:///<DB_NAME>?cloudSqlInstance=<CLOUD_SQL_CONNECTION_NAME>& | ||
| 55 | + // socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=<DB_USER>&password=<DB_PASS> | ||
| 56 | + // See the link below for more info on building a JDBC URL for the Cloud SQL JDBC Socket Factory | ||
| 57 | + // https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory#creating-the-jdbc-url | ||
| 58 | + | ||
| 53 | 59 | // Configure which instance and what database user to connect with. | |
| 54 | 60 | config.setJdbcUrl(String.format("jdbc:postgresql:///%s", DB_NAME)); | |
| 55 | 61 | config.setUsername(DB_USER); // e.g. "root", "postgres" | |
@@ -60,6 +66,8 @@ private DataSource createConnectionPool() { | |||
| 60 | 66 | config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory"); | |
| 61 | 67 | config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME); | |
| 62 | 68 | ||
| 69 | + | ||
| 70 | + | ||
| 63 | 71 | // ... Specify additional connection properties here. | |
| 64 | 72 | // [START_EXCLUDE] | |
| 65 | 73 | ||
@@ -110,7 +118,7 @@ private void createTable(DataSource pool) throws SQLException { | |||
| 110 | 118 | "CREATE TABLE IF NOT EXISTS votes ( " | |
| 111 | 119 | + "vote_id SERIAL NOT NULL, time_cast timestamp NOT NULL, candidate CHAR(6) NOT NULL," | |
| 112 | 120 | + " PRIMARY KEY (vote_id) );"; | |
| 113 | - try (PreparedStatement createTableStatement = conn.prepareStatement(stmt); ) { | ||
| 121 | + try (PreparedStatement createTableStatement = conn.prepareStatement(stmt);) { | ||
| 114 | 122 | createTableStatement.execute(); | |
| 115 | 123 | } | |
| 116 | 124 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments