/
.readme-partials.yaml
36 lines (29 loc) · 1.15 KB
/
.readme-partials.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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());
}
}
}
}
```
### Creating a Shaded Jar
A jar with all dependencies included is automatically generated when you execute `mvn package`.
The dependencies in this jar are not shaded. To create a jar with shaded dependencies you must
activate the `shade` profile like this:
```
mvn package -Pshade
```