我正在尝试构建一个poc,后端是cassandra,前端是j2ee。我已经将cassandra lib文件夹中可用的jar文件添加到我的java id(eclipse)中。但是在这种背景下没有认识到几种api方法!
是否有任何需要添加cassandra的驱动程序jar,如oracle或sybase一样?
答案 0 :(得分:1)
你的j2ee中不需要cassandra罐子。官方客户端API是Thrift,这是一个关于如何使用thrift连接的java示例 - http://wiki.apache.org/cassandra/ThriftExamples
有一些java包装器可供Thrift与Cassandra连接(因为Thrift API不是非常用户友好)。 其中我强烈推荐Hector - http://prettyprint.me/2010/02/23/hector-a-java-cassandra-client/
答案 1 :(得分:0)
你为什么不试试赫克托耳: https://github.com/rantav/hector
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.MutationResult;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;
import me.prettyprint.hector.api.query.QueryResult;
// sample connect method in Java
private static void connect() {
Cluster cluster;
Keyspace keyspace;
StringSerializer se = new StringSerializer();
cluster = HFactory.getOrCreateCluster("TestCluster", new CassandraHostConfigurator("localhost:9160"));
keyspace = HFactory.createKeyspace("Twissandra", cluster);
Mutator<String> mutator = HFactory.createMutator(keyspace, se)
MutationResult rs = mutator.insert("some-name-key", "User",
HFactory.createStringColumn("first", "some value"));