How to use Java to operate CrateDB

To use Java to operate CrateDB, you need to add the following Maven dependencies: <dependency> <groupId>io.crate</groupId> <artifactId>crate-client</artifactId> <version>VERSION</version> </dependency> Please replace 'VERSION' with the version of CrateDB you want to use. The following is a sample code for Java implementation of data addition, deletion, modification, and query: import io.crate.action.sql.SQLActionException; import io.crate.client.CrateClient; import io.crate.client.CrateClientFactory; import io.crate.client.ResultReceiver; import io.crate.data.Row; import io.crate.data.Row1; import io.crate.data.RowN; import io.crate.user.User; import java.net.InetSocketAddress; import java.util.List; import java.util.Map; public class CrateDBExample { public static void main(String[] args) { //Create CrateDB client CrateClient crateClient = CrateClientFactory.fromHosts(List.of(new InetSocketAddress("localhost", 5432))); try { //Create Table crateClient.execute("CREATE TABLE IF NOT EXISTS my_table (id INT PRIMARY KEY, name STRING)"); //Insert Data crateClient.execute("INSERT INTO my_table (id, name) VALUES (?, ?)", new Object[]{1, "John Doe"}); //Query data crateClient.execute("SELECT id, name FROM my_table", new ResultReceiver<Row>() { @Override public void setNextRow(Row row) { System.out.println(row); } @Override public void setColumns(List<? extends DataType> dataTypes) { //Can save column metadata as needed } @Override public void success(long rowCount) { System.out.println("Query executed successfully"); } @Override public void fail(Throwable throwable) { System.out.println("Query failed: " + throwable.getMessage()); } }); //Update data crateClient.execute("UPDATE my_table SET name = ? WHERE id = ?", new Object[]{"Jane Smith", 1}); //Delete data crateClient.execute("DELETE FROM my_table WHERE id = ?", new Object[]{1}); } catch (SQLActionException e) { //Handling SQL operation exceptions System.out.println("SQL action failed: " + e.getMessage()); } finally { //Close client connection crateClient.close(); } } } In the above example, we first created a CrateDB client using the 'CrateClientFactory. FromHosts()' method and specified the host address and port number of CrateDB. Then, we can perform various SQL operations, such as creating tables, inserting data, querying data, updating data, and deleting data. For query operations, we need to provide a callback object that implements the 'ResultReceiver' interface to handle the returned results. Please modify the host address and port number according to the actual situation, and adjust the sample code according to your needs.