Help Center/
GeminiDB/
GeminiDB Cassandra API/
Working with GeminiDB Cassandra API/
Instance Connections/
Connecting to an Instance Using Java
Updated on 2024-10-30 GMT+08:00
Connecting to an Instance Using Java
This section describes how to use the Java to connect to a GeminiDB Cassandra instance.
Prerequisites
- A GeminiDB Cassandra instance has been created and is running properly. For details about how to create a GeminiDB Cassandra instance, see Buying an Instance.
- For details about how to create an ECS, see Purchasing an ECS in Getting Started with Elastic Cloud Server.
- JDK has been installed on the ECS.
- DataStax 3.11.x is recommended. DataStax 4.x is not supported.
Procedure
- Obtain the private IP address and port number of the GeminiDB Cassandra instance.
For details about how to obtain the private IP address and port number, see Viewing the IP Address and Port Number.
- Log in to the ECS. For details, see Logging In to an ECS in Getting Started with Elastic Cloud Server.
- Edit the code for connecting to the GeminiDB Cassandra instance.
import com.datastax.driver.core.*; Cluster cluster = null; try { cluster = Cluster.builder() .addContactPoint("127.0.0.1")//Private IP address of the GeminiDB Cassandra instance obtained in step 1 .withPort(8635) //Port number of the GeminiDB Cassandra instance obtained in step 1 .build(); Session session = cluster.connect(); ResultSet rs = session.execute("select release_version from system.local"); Row row = rs.one(); System.out.println(row.getString("release_version")); } finally { if (cluster != null) cluster.close(); }
- Run the sample code to check whether the result is normal.
Parent topic: Instance Connections
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot