问题
I want to use a method that can insert data into my cassandra database , I was able to get data by doing this method
public JSONArray getData() {
StringBuilder sb
= new StringBuilder("SELECT * FROM ").append("user");
String query = sb.toString();
ResultSet rs = session.execute(query);
JSONArray users = new JSONArray();
rs.forEach(r -> {
JSONObject user = new JSONObject();
users.put(
user.put("name", r.getString("name")).put("email", r.getString("email")));
});
return users;
}
but I dont know how to insert data into database , I tried this but doesn't work :
public String insertData(String name, String email, String password,String confirmpassword) {
StringBuilder sb = new StringBuilder("INSERT INTO user_keyspace.user(name,email,password,confirmpassword) VALUES ('" +
name + "','" + email + "','" + password + "','" + confirmpassword +"')");
String query = sb.toString();
session.execute(query);
return"Record inserted successfully";
}
any suggestions !!!
来源:https://stackoverflow.com/questions/65884945/create-new-record-into-cassandra-db-using-java-restful-web-service