com.google.cloud.spanner.jdbc

## Class JdbcDriver

- java.lang.Object
- - com.google.cloud.spanner.jdbc.JdbcDriver

All Implemented Interfaces:
  Driver

    public class JdbcDriver
    extends Object
    implements Driver

JDBC `Driver` for Google Cloud Spanner.

Usage:

     String url = "jdbc:cloudspanner:/projects/my_project_id/"
                + "instances/my_instance_id/databases/my_database_name?"
                + "credentials=/home/cloudspanner-keys/my-key.json;autocommit=false";
     try (Connection connection = DriverManager.getConnection(url)) {
       try(ResultSet rs = connection.createStatement().executeQuery("SELECT SingerId, AlbumId, MarketingBudget FROM Albums")) {
         while(rs.next()) {
           // do something
         }
       }
     }

The connection that is returned will implement the interface `CloudSpannerJdbcConnection`. The JDBC connection URL must be specified in the following format:

     jdbc:cloudspanner:[//host[:port]]/projects/project-id[/instances/instance-id[/databases/database-name]][\?property-name=property-value[;property-name=property-value]*]?

The property-value strings should be url-encoded.

The project-id part of the URI may be filled with the placeholder DEFAULT_PROJECT_ID. This placeholder will be replaced by the default project id of the environment that is requesting a connection.

The supported properties are:

- credentials (String): URL for the credentials file to use for the connection. If you do not specify any credentials at all, the default credentials of the environment as returned by `GoogleCredentials.getApplicationDefault()` will be used.
- oauthtoken (String): A valid OAuth2 token to use for the JDBC connection. The token must have been obtained with one or both of the scopes 'https://www.googleapis.com/auth/spanner.admin' and/or 'https://www.googleapis.com/auth/spanner.data'. If you specify both a credentials file and an OAuth token, the JDBC driver will throw an exception when you try to obtain a connection.
- autocommit (boolean): Sets the initial autocommit mode for the connection. Default is true.
- readonly (boolean): Sets the initial readonly mode for the connection. Default is false.
- retryAbortsInternally (boolean): Sets the initial retryAbortsInternally mode for the connection. Default is true. @see `CloudSpannerJdbcConnection.setRetryAbortsInternally(boolean)` for more information.

### Constructor Summary

Constructors
Constructor and Description
`JdbcDriver()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`boolean` `acceptsURL(String url)`
`Connection` `connect(String url, Properties info)`
`static String` `getClientLibToken()`
`int` `getMajorVersion()`
`int` `getMinorVersion()`
`Logger` `getParentLogger()`
`DriverPropertyInfo[]` `getPropertyInfo(String url, Properties info)`
`boolean` `jdbcCompliant()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### JdbcDriver

    public JdbcDriver()

### Method Detail

#### getClientLibToken

    @InternalApi
    public static String getClientLibToken()

#### connect

    public Connection connect(String url,
                              Properties info)
                       throws SQLException

Specified by:
  `connect` in interface `Driver`
Throws:
  `SQLException`

#### acceptsURL

    public boolean acceptsURL(String url)
                       throws SQLException

Specified by:
  `acceptsURL` in interface `Driver`
Throws:
  `SQLException`

#### getPropertyInfo

    public DriverPropertyInfo[] getPropertyInfo(String url,
                                                Properties info)
                                         throws SQLException

Specified by:
  `getPropertyInfo` in interface `Driver`
Throws:
  `SQLException`

#### getMajorVersion

    public int getMajorVersion()

Specified by:
  `getMajorVersion` in interface `Driver`

#### getMinorVersion

    public int getMinorVersion()

Specified by:
  `getMinorVersion` in interface `Driver`

#### jdbcCompliant

    public boolean jdbcCompliant()

Specified by:
  `jdbcCompliant` in interface `Driver`

#### getParentLogger

    public Logger getParentLogger()
                           throws SQLFeatureNotSupportedException

Specified by:
  `getParentLogger` in interface `Driver`
Throws:
  `SQLFeatureNotSupportedException`