Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#JDBC driver for Google Cloud Spanner
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this - you can address this in the next commit, but this needs a space between the # and JDBC. Also, please capitalize Driver

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, NP.


JDBC driver for
[Google Cloud Spanner](https://cloud.google.com/spanner/).

## Quickstart

[//]: # ({x-version-update-start:google-cloud-spanner-jdbc:released})
If you are using Maven, add this to your pom.xml file
```xml
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-jdbc</artifactId>
<version>0.1.0</version>
</dependency>
```
If you are using Gradle, add this to your dependencies
```Groovy
compile 'com.google.cloud:google-cloud-spanner-jdbc:0.1.0'
```
If you are using SBT, add this to your dependencies
```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner-jdbc" % "0.1.0"
```
[//]: # ({x-version-update-end})

## Getting Started
You can access Google Cloud Spanner through JDBC like this:

```java
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()) {
Long singerId = rs.getLong(1);
}
}
}
```

### Connection URL
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 connection properties are:

* credentials (String): URL for the credentials file to use for the connection. If you do not specify any credentials, the default credentials of the environment as returned by {@link GoogleCredentials#getApplicationDefault()} will be used.
* 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.

### Authentication
The JDBC driver will either use the credentials that are specified in the connection URL, or if none specified, the default credentials of the environment.

See the
[Authentication](https://github.com/googleapis/google-cloud-java#authentication)
section in the base directory's README for more information.

## Examples

The google-cloud-spanner-jdbc-examples project contains a number of examples on how to use the JDBC driver. These include:

* JdbcConnectExamples: Contains examples on how to obtain a JDBC connection for Cloud Spanner.
* JdbcAutocommitExamples: Contains examples on how to use a JDBC connection in autocommit mode.
* JdbcTransactionExamples: Contains examples on how to use the JDBC connection with read/write and read-only transactions.
* JdbcBatchExamples: Shows the batching capabilities of the Cloud Spanner JDBC driver.
* JdbcVariablesExamples: Shows how to use custom SQL statements to read and write variables from a JDBC connection.
* JdbcCustomMethodsExample: Shows how to use the custom methods that are exposed by the `com.google.cloud.spanner.jdbc.CloudSpannerJdbcConnection` interface.


## Shaded JAR

You can build a shaded JAR of the JDBC driver to use with third-party tools using the following command:

```
mvn package -Pbuild-jdbc-driver
```

## Java Versions

Java 7 or above is required for using this JDBC driver.

## Versioning

This library follows [Semantic Versioning](http://semver.org/).

## Contributing

Contributions to this library are always welcome and highly encouraged.

See `google-cloud`'s [CONTRIBUTING] documentation and the
[shared documentation](https://github.com/googleapis/google-cloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud)
for more information on how to get started.

Please note that this project is released with a Contributor Code of Conduct.
By participating in this project you agree to abide by its terms. See
[Code of Conduct][code-of-conduct] for more information.

## License

Apache 2.0 - See [LICENSE] for more information.


[CONTRIBUTING]:https://github.com/googleapis/google-cloud-java/blob/master/CONTRIBUTING.md
[code-of-conduct]:https://github.com/googleapis/google-cloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
[LICENSE]: https://github.com/googleapis/google-cloud-java/blob/master/LICENSE
[cloud-platform]: https://cloud.google.com/

[cloud-spanner]: https://cloud.google.com/spanner/
[cloud-spanner-docs]: https://cloud.google.com/spanner/docs/overview
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>google-cloud-spanner-jdbc</artifactId>
<version>0.1.0</version><!-- {x-version-update:google-cloud-spanner-jdbc:current} -->
<packaging>jar</packaging>
<name>Google Cloud Spanner JDBC</name>
<url>https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-contrib/google-cloud-spanner-jdbc</url>
<description>
JDBC driver for Google Cloud Spanner.
</description>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-contrib</artifactId>
<version>0.101.0-alpha</version><!-- {x-version-update:google-cloud-contrib:current} -->
</parent>
<properties>
<site.installationModule>google-cloud-spanner-jdbc</site.installationModule>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>google-cloud-spanner</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>1.28.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
<classifier>testlib</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<excludedGroups>com.google.cloud.spanner.IntegrationTest,com.google.cloud.spanner.stresstest.StressTest</excludedGroups>
<reportNameSuffix>sponge_log</reportNameSuffix>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<systemPropertyVariables>
<spanner.testenv.config.class>com.google.cloud.spanner.GceTestEnvConfig</spanner.testenv.config.class>
<spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing</spanner.testenv.instance>
</systemPropertyVariables>
<groups>com.google.cloud.spanner.IntegrationTest</groups>
<excludedGroups>com.google.cloud.spanner.FlakyTest,com.google.cloud.spanner.stresstest.StressTest</excludedGroups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- Profile for generating new sql test scripts. See ConnectionImplGeneratedSqlScriptTest
for more information. -->
<id>generate-test-sql-scripts</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>generateTestScripts</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.google.cloud.spanner.jdbc.SqlTestScriptsGenerator</mainClass>
<systemProperties>
<systemProperty>
<key>do_log_statements</key>
<value>true</value>
</systemProperty>
</systemProperties>
<classpathScope>test</classpathScope>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- Profile for building a jar containing all dependencies and the
JDBC driver. This jar can then be used with third-party tools that support
generic JDBC drivers to connect to Cloud Spanner databases. -->
<id>build-jdbc-driver</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createSourcesJar>true</createSourcesJar>
<shadeSourcesContent>true</shadeSourcesContent>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
<excludes>
<exclude>java:*</exclude>
<exclude>junit:*</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>META-INF/services</resource>
<file>java.sql.Driver</file>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>com.google.cloud.spanner.jdbc</resource>
<file>ClientSideStatements.json</file>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>com.google.cloud.spanner.jdbc</resource>
<file>*.sql</file>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
1 change: 1 addition & 0 deletions versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ google-cloud-resourcemanager:0.101.0-alpha:0.101.0-alpha
google-cloud-scheduler:1.6.0:1.6.0
google-cloud-securitycenter:0.101.0:0.101.0
google-cloud-spanner:1.28.0:1.28.0
google-cloud-spanner:0.1.0:0.1.0
google-cloud-speech:1.13.0:1.13.0
google-cloud-storage:1.83.0:1.83.0
google-cloud-talent:0.18.0-beta:0.18.0-beta
Expand Down