How to Specify a DPS Cluster
When using Relyt, in addition to directly selecting a DPS cluster in a workbook, there are also two other ways to specify a DPS cluster:
-
Specify via SQL statement
-
Specify in
username
when connecting to a database
Specify via SQL statement
You can specify a using the SET
statement. The syntax is as follows:
SET relyt.dpsname = <dps_name>
For example, to use a DPS cluster named mydps-test
, you can execute the following SQL statement:
SET relyt.dpsname = 'mydps-test'
Specify in username
When connecting to a database, you can append relyt.dpsname=<dps_name>
to the end of <username>
.
Here is a Java example:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class PostgresJDBCExample {
public static void main(String[] args) {
// Database connection information
String url = "jdbc:postgresql://127.0.0.1:5432/postgres";
String user = "postgres?relyt.dpsname=mydps-test";
String password = "yourpassword";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Load PostgreSQL JDBC driver
Class.forName("org.postgresql.Driver");
// Establish connection
conn = DriverManager.getConnection(url, user, password);
System.out.println("Connection successful!");
// Create a Statement object to execute SQL query
stmt = conn.createStatement();
String sql = "show relyt.dpsname";
// Execute query and get result set
rs = stmt.executeQuery(sql);
// Process result set
while (rs.next()) {
System.out.println(rs.getString(1));
// Handle other columns as needed
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close resources
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}