我想知道使用BoundStatement
相比于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");
最简单的方法是:
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");
正如您所看到的,我可以在不使用boundStatements
的情况下将数据绑定到preparedStatement
中。那么boundStatement
在哪些情况下会发挥重要作用呢?