Java SDK
GreptimeDB Java SDK 使用 gRPC 与数据库通信, 请参考 Java SDK 文档查看更多 SDK 使用的相关内容。
请使用以下信息连接到 GreptimeCloud:
- Host:
<host> - Port:
4001 - Database:
<dbname> - Username:
<username> - Password: Your GreptimeCloud service password
下方的代码片段展示了如何使用 Java SDK 建立一个 client 连接对象:
java
1. String endpoint = "<host>:4001";
2. AuthInfo authInfo = new AuthInfo("<username>", "*Your GreptimeCloud service password*");
4. GreptimeOptions opts = GreptimeOptions.newBuilder(endpoint) //
5. .authInfo(authInfo)
6. .writeMaxRetries(1) //
7. .readMaxRetries(2) //
8. .routeTableRefreshPeriodSeconds(-1) //
9. .build();
11. GreptimeDB greptimeDB = new GreptimeDB();
13. if (!greptimeDB.init(opts)) {
14. throw new RuntimeException("Fail to start GreptimeDB client");
15. }
在创建了 GreptimeDB 客户端之后,你可以在写入数据或查询数据时设置数据库。例如查询数据:
java
1. QueryRequest request = QueryRequest.newBuilder() //
2. .exprType(SelectExprType.Sql) //
3. .ql("SELECT * FROM monitor;") //
4. .databaseName("<dbname>") //
5. .build();
