Prepared statements against Related statements in Kassandra?

I am wondering what is the advantage of using BoundStatementover PreparedStatement?

PreparedStatement statement = session.prepare(
                      "INSERT INTO simplex.songs " +
                      "(id, title, album, artist) " +
                      "VALUES (?, ?, ?, ?);");

BoundStatement boundStatement = new BoundStatement(statement);
            session.execute(boundStatement.bind(
                  UUID.fromString("756716f7-2e54-4715-9f00-91debea6cf50"),
                  "La Petite Tonkinoise",
                  "Bye Bye Blackbird",
                  "Joséphine Baker");

The easiest way:

PreparedStatement ps = session.prepare(
                      "INSERT INTO simplex.songs " +
                      "(id, title, album, artist, tags) " +
                      "VALUES (?, ?, ?, ?, ?);");
ps.bind(UUID.fromString("756716f7-2e54-4715-9f00-91debea6cf50"),
                      "La Petite Tonkinoise",
                      "Bye Bye Blackbird",
                      "Joséphine Baker");

As you can see, I can bind data to PreparedStatementwithout boundStatements. Where BoundStatementis useful?

+4
source share
2 answers

No advantage: BoundStatement is nothing like a PreparedStatement with limited variables. The bind()PreparedStatements method essentially returns a BoundStatement.

+5
source

BoundStatement , bind (...) PreparedStatement. BoundStatement.

PreparedStatement BoundStatement , PreparedStatement.bind() BoundStatement, BoundStatement.bind() .

. .bind() BoundStatement

// shared instance BoundStatement on few threads 
BoundStatement bs1 = 
// bs2 is the same as bs1
// param1, param2, ... are different for every thread
BoundStatement bs2 = bs1.bind(param1, param2, ...);
// add some time to wait so other thread can modify your params
// Thread.sleep(RandomUtils.nextInt(100));        
// result2 sometimes may be with incorrect result 
results2 = session.execute(bs2); 

bind PreparedStatement , . ( , )

PreparedStatement ps1 = 
BoundStatement bs2 = ps1.bind(param1, param2, ...);
results2 = session.execute(bs2); 
0

All Articles