连接 cassandra 数据库是否需要任何驱动程序 jar

发布于 2024-10-27 06:33:33 字数 201 浏览 4 评论 0原文

我正在尝试构建一个 poc,其中后端是 cassandra,前端是 j2ee。我已将 cassandra lib 文件夹中可用的 jar 文件添加到我的 java id(eclipse) 中。但在这种情况下,有几个 api 方法不被识别!

是否有像 oracle 或 sybase 一样需要添加的 cassandra 驱动程序 jar?

I am trying to build a poc where back-end is cassandra and front end is j2ee. I have added the jar files available in cassandra lib folder into my java id(eclipse). But several api method is not being recognized in this context!

Is there any driver jar for cassandra that needs to be added as in case of oracle or sybase?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-小熊_ 2024-11-03 06:33:33

您的 j2ee 中不需要 cassandra jar。官方客户端 API 是 Thrift,这里有一个关于如何使用 thrift 连接的 java 示例 -
http://wiki.apache.org/cassandra/ThriftExamples

有一些 java 包装器可用于Thrift 与 Cassandra 连接(因为 Thrift API 对用户不太友好)。
其中我强烈推荐赫克托——
http://prettyprint.me/2010/02/23/ hector-a-java-cassandra-client/

You don't need cassandra jars in your j2ee. The official client side API is Thrift, here's a java example on how to connect using thrift -
http://wiki.apache.org/cassandra/ThriftExamples

there are a few java wrappers available for Thrift to connect with Cassandra (as Thrift API is not very user friendly).
Among them I can highly recommend Hector -
http://prettyprint.me/2010/02/23/hector-a-java-cassandra-client/

双手揣兜 2024-11-03 06:33:33

你为什么不试试赫克托:
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"));

Why don't you try Hector:
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"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文