private static void insertWithCoreApi ( CqlSession session ) { // Bind in a simple statement: session . execute ( SimpleStatement . newInstance ( "INSERT INTO examples.querybuilder_json JSON ?" , "{ \"id\": 1, \"name\": \"Mouse\", \"specs\": { \"color\": \"silver\" } }" ) ) ; // Bind in a prepared statement: // (subsequent calls to the prepare() method will return cached statement) PreparedStatement pst = session . prepare ( "INSERT INTO examples.querybuilder_json JSON :payload" ) ; session . execute ( pst . bind ( ) . setString ( "payload" , "{ \"id\": 2, \"name\": \"Keyboard\", \"specs\": { \"layout\": \"qwerty\" } }" ) ) ; // fromJson lets you provide individual columns as JSON: session . execute ( SimpleStatement . newInstance ( "INSERT INTO examples.querybuilder_json " + "(id, name, specs) VALUES (?, ?, fromJson(?))" , 3 , "Screen" , "{ \"size\": \"24-inch\" }" ) ) ; }
Demonstrates data insertion with the core API i . e . providing the full query strings .