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 is replaced by the default project id of the environment that is requesting a connection.
The supported properties are:
GoogleCredentials.getApplicationDefault() is used.
LATEST. If no value is specified, the
query optimizer version specified in the environment variable
SPANNER_OPTIMIZER_VERSION is used. If no query optimizer version is specified in the
connection URL or in the environment variable, the default query optimizer version of Cloud
Spanner is 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)
acceptsURL in interface Driverpublic DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
getPropertyInfo in interface Driverpublic 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 © 2023 Google LLC. All rights reserved.