create new record into cassandra DB using java RESTful web service

落花浮王杯 提交于 2021-02-17 07:05:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!