我是 cassandra 和 moven 的新手。我试图在 eclipse 中编写一个简单的 java 程序,它使用 cassandra java 驱动程序连接到我设置的 cassandra 节点。 我找到了这个存储库 https://github.com/datastax/java-driver但我不知道我应该用它做什么。任何人都可以给我逐步说明以获取驱动程序并创建一个使用该驱动程序的简单 eclipse 项目。
最佳答案
- 启动Eclipse(确保eclipse有maven,我用的是eclipse KEPLER)
- 新建一个eclipse项目(在Maven文件夹下选择“Maven Project”)
- 给项目起个名字/group-id/artifact-id
- 打开pom.xml,然后单击实际的pom.xml 选项卡。
- 添加 github 上显示的依赖项,我的 pom 文件最终看起来像 this .
最后写一个类来用驱动程序做一些事情,下面创建一个键空间和一个列族。
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
public class App
{
public static void main( String[] args )
{
Cluster cluster = Cluster.builder()
.addContactPoints("127.0.0.1")
.build();
Session session = cluster.connect();
String cqlStatement = "CREATE KEYSPACE myfirstcassandradb WITH " +
"replication = {'class':'SimpleStrategy','replication_factor':1}";
session.execute(cqlStatement);
String cqlStatement2 = "CREATE TABLE myfirstcassandradb.users (" +
" user_name varchar PRIMARY KEY," +
" password varchar " +
");";
session.execute(cqlStatement2);
System.out.println("Done");
System.exit(0);
}
}
另请查看 CRUD operations 的答案与司机。
关于java - 如何使用 Eclipse 设置 Cassandra Java 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21517338/