本文介绍了使用Cassandra Operations Spring Boot使用Cassandra Prepared语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要准备语句/而不是使用Cassandra Operations Interface和会话
任何示例或最新文档的查询生成器。对于使用Java的Cassandra

I need Prepared Statement / instead of Query Builder using Cassandra Operations Interface and sessionAny Example or recent docs. for Cassandra using java

推荐答案

对于spring-data-cassandra v1.x, getSession() 可让您直接访问 Session 。但是,自v2.0以来,不再推荐使用类似的API

For spring-data-cassandra v1.x, the getSession() method of org.springframework.cassandra.core.CqlOperations could let you access Session directly. However, similar APIs are deprecated since v2.0

此处是

@Autowired
private CqlOperations cqlTemplate;//or inherited interface, like CassandraOperations

private void insertEventUsingPreparedStatement() {
  PreparedStatement preparedStatement = cqlTemplate.getSession().prepare("insert into event (id, type, bucket, tags) values (?, ?, ?, ?)");
  Statement insertStatement = preparedStatement.bind(UUIDs.timeBased(), "type2", TIME_BUCKET, ImmutableSet.of("tag1", "tag2"));
  cqlTemplate.execute(insertStatement);
}

这篇关于使用Cassandra Operations Spring Boot使用Cassandra Prepared语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:37