how to setup cassandra java driver with eclipse
cassandra, driver, java
Solution
- Start Eclipse (make sure eclipse has maven, I used eclipse KEPLER)
- Create a new eclipse project (Under the Maven folder select "Maven Project")
- Give the project a name / group-id / artifact-id
- Open pom.xml and then click on the actual pom.xml tab.
- Add the dependency shown on github, my pom file ended up looking like this.
And finally write a class to do some stuff with the driver, the below creates a keyspace and a column family.
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);
}
}
Also check this answer out for CRUD operations with the driver.
Problem
I am new to cassandra and moven. I was trying to write a simple java program in eclipse that uses cassandra java driver to connect to a cassandra node I have setup. I found this repository https://github.com/datastax/java-driver but I have no idea what I should do with it. Can anyone give me step by step instructions for getting the driver and creating a simple eclipse project that uses the driver.