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 Driver
SQLException
public boolean acceptsURL(String url)
acceptsURL
in interface Driver
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
getPropertyInfo
in interface Driver
public int getMajorVersion()
getMajorVersion
in interface Driver
public int getMinorVersion()
getMinorVersion
in interface Driver
public boolean jdbcCompliant()
jdbcCompliant
in interface Driver
public Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger
in interface Driver
SQLFeatureNotSupportedException
Copyright © 2023 Google LLC. All rights reserved.