Skip to content

Commit

Permalink
docs: add connection example to readme (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Nov 27, 2020
1 parent 1ab5af2 commit 00314e6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .readme-partials.yaml
@@ -0,0 +1,25 @@
custom_content: |
### Creating a JDBC Connection
The following example shows how to create a JDBC connection to Cloud Spanner and execute a simple query.
```java
String projectId = "my-project";
String instanceId = "my-instance";
String databaseId = "my-database";
try (Connection connection =
DriverManager.getConnection(
String.format(
"jdbc:cloudspanner:/projects/%s/instances/%s/databases/%s",
projectId, instanceId, databaseId))) {
try (Statement statement = connection.createStatement()) {
try (ResultSet rs = statement.executeQuery("SELECT CURRENT_TIMESTAMP()")) {
while (rs.next()) {
System.out.printf(
"Connected to Cloud Spanner at [%s]%n", rs.getTimestamp(1).toString());
}
}
}
}
```

0 comments on commit 00314e6

Please sign in to comment.