public class JdbcDriver extends Object implements Driver
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:
GoogleCredentials.getApplicationDefault() will be used.
CloudSpannerJdbcConnection.setRetryAbortsInternally(boolean)
for more information.
| Constructor and Description |
|---|
JdbcDriver() |
| Modifier and Type | Method and Description |
|---|---|
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() |
@InternalApi public static String getClientLibToken()
public Connection connect(String url, Properties info) throws SQLException
connect in interface DriverSQLExceptionpublic boolean acceptsURL(String url) throws SQLException
acceptsURL in interface DriverSQLExceptionpublic DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException
getPropertyInfo in interface DriverSQLExceptionpublic int getMajorVersion()
getMajorVersion in interface Driverpublic int getMinorVersion()
getMinorVersion in interface Driverpublic boolean jdbcCompliant()
jdbcCompliant in interface Driverpublic Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger in interface DriverSQLFeatureNotSupportedExceptionCopyright © 2019 Google LLC. All rights reserved.