package com.company.cassandra;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Cluster.Builder;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
public class CassandraExport {
public static Session session;
public static void connect(String username, String password, String host, int port, String keyspace) {
Builder builder = Cluster.builder().addContactPoint(host);
builder.withPort(port);
if (username != null && password != null) {
builder.withCredentials(username, password);
}
Cluster cluster = builder.build();
session = cluster.connect(keyspace);
}
public static void main(String[] args) {
//Prod
connect("user", "password", "server", 9042, "keyspace");
ResultSetFuture future = session.executeAsync("SELECT * FROM table;");
ResultSet results = future.getUninterruptibly();
for (Row row : results) {
//Print the columns in the following order
String out = row.getString("col1") + "\t" +
String.valueOf(row.getInt("col2")) + "\t" +
String.valueOf(row.getLong("col3")) + "\t" +
String.valueOf(row.getLong("col4"));
System.out.println(out);
}
session.close();
session.getCluster().close();
}
}