-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathArtSchoolRetriever.java
More file actions
48 lines (35 loc) · 1.94 KB
/
ArtSchoolRetriever.java
File metadata and controls
48 lines (35 loc) · 1.94 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
import com.couchbase.client.core.error.CouchbaseException;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.json.JsonObject;
import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryResult;
import com.couchbase.client.java.ClusterOptions;
public class ArtSchoolRetrieverParameters {
public static void main(String[] args) {
String connectionString = "<<connection-string>>"; // Replace this with Connection String
String username = "<<username>>"; // Replace this with username from cluster access credentials
String password = "<<password>>"; // Replace this with password from cluster access credentials
Cluster cluster = Cluster.connect(connectionString, ClusterOptions.clusterOptions(username, password)
.environment(env -> env.applyProfile("wan-development"))
);
retrieveCourses(cluster);
cluster.disconnect();
}
private static void retrieveCourses(Cluster cluster) {
try {
// This SQL++ statement takes the parameter `$creditPopints`,
// which is then substituted by the value in the second parameter when the statement is called.
final QueryResult result = cluster.query("select crc.* " +
"from `student-bucket`.`art-school-scope`.`course-record-collection` crc " +
"where crc.`credit-points` < $creditPoints",
// The second parameter in the function call, with a value that replaces `$creditPoints`.
QueryOptions.queryOptions()
.parameters(JsonObject.create().put("creditPoints", 200)));
for (JsonObject row : result.rowsAsObject()) {
System.out.println("Found row: " + row);
}
} catch (CouchbaseException ex) {
ex.printStackTrace();
}
}
}