GoogleCloudPlatform/cloud-sql-jdbc-socket-factory

Name: cloud-sql-jdbc-socket-factory

Owner: Google Cloud Platform

Description: null

Created: 2016-03-23 17:58:22.0

Updated: 2018-05-24 12:49:12.0

Pushed: 2018-05-08 20:35:35.0

Homepage: null

Size: 119

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Cloud SQL Socket Factory for JDBC drivers

The Cloud SQL Socket Factory is a library for the MySQL/Postgres JDBC drivers that allows a user with the appropriate permissions to connect to a Cloud SQL database without having to deal with IP whitelisting or SSL certificates manually.

Instructions

The library is available in Maven Central.

Add a dependency using your favorite build tool. Maven and Gradle examples are shown below.

MySQL

Note: If you wish to use the 6.x (development) version of the MySQL driver, use the artifact id 'mysql-socket-factory-connector-j-6'.

Adding dependency (Maven)
endency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.8</version>
pendency>
Adding dependency (Gradle)
ile 'com.google.cloud.sql:mysql-socket-factory:1.0.8'
Using

When specifying the JDBC connection URL, add two additional parameters:

| Property | Value | | —————- | ————- | | socketFactory | com.google.cloud.sql.mysql.SocketFactory | | cloudSqlInstance | The instance connection name (which is found on the instance details page in Google Developers Console) |

For example, if the instance connection name is foo:bar:baz, the JDBC URL would be jdbc:mysql://google/mydb?socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=foo:bar:baz

A tool is available in examples/getting-started that can help generate the JDBC URL and verify that connectivity can be established.

PostgreSQL
Adding dependency (Maven)
endency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
<version>1.0.8</version>
pendency>
Adding dependency (Gradle)
ile 'com.google.cloud.sql:postgres-socket-factory:1.0.8'
Using

When specifying the JDBC connection URL, add two additional parameters:

| Property | Value | | —————- | ————- | | socketFactory | com.google.cloud.sql.postgres.SocketFactory | | socketFactoryArg | The instance connection name (which is found on the instance details page in Google Developers Console) |

For example, if the instance connection name is foo:bar:baz, the JDBC URL would be jdbc:postgresql://google/mydb?socketFactory=com.google.cloud.sql.postgres.SocketFactory&socketFactoryArg=foo:bar:baz

A tool is available in examples/getting-started that can help generate the JDBC URL and verify that connectivity can be established.

Credentials

The library needs to obtain credentials in order to retrieve SSL certificates that are used to connect to the instance. Application Default Credentials are used for this purpose.

On Google Compute Engine and Google App Engine, the VM/application service account is used.

For local development, application default credentials written by gcloud are used, if present. You must run gcloud auth application-default login once for the credentials to become available to the library.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.