【发布时间】:2014-09-27 14:36:51
【问题描述】:
我想知道使用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在哪里有用?
【问题讨论】:
标签: prepared-statement cassandra-2.0 datastax-java-driver