下面是使用准备好的语句插入有关图像的数据的代码示例。
PreparedStatement statement = getSession().prepare(
"INSERT INTO pixelstore.image " +
"(image_name, " +
" upload_time, " +
" upload_by, " +
" file_type, " +
" file_size" +
") VALUES (?, ?, ?, ?, ?);");
// create the bound statement and initialise it with your prepared statement
BoundStatement boundStatement = new BoundStatement(statement);
session.execute( // this is where the query is executed
boundStatement.bind( // here you are binding the 'boundStatement'
"background", TimeUtil.getTimeUUID(), "lyubent", "png", "130527"));
最近有两篇关于 cassandra 星球的博客文章,其中包含驱动程序可以做什么的演示,它们包含代码示例,因此请查看它们:
- 使用 Cassandra 和 DataStax Java 驱动程序的物化视图
- 使用 DataStax Java 驱动程序和 Cassandra 1.2 工作的小型 Java 应用程序