Last active
August 29, 2015 14:27
-
-
Save eribeiro/cb56900148ff7b7a0b41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.datastax.driver.core.*; | |
import java.util.Arrays; | |
import java.util.UUID; | |
// create keyspace test with replication = {'class': 'SimpleStrategy', 'replication_factor': 1}; | |
// create table t2 (id uuid primary key, value list<text>); | |
public class CassandraTest { | |
public static void main(String[] args) | |
{ | |
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build(); | |
Session session = cluster.connect("test"); | |
PreparedStatement preparedStatement = session.prepare("INSERT INTO t2 (id, value) values (?, ?)"); | |
BoundStatement boundStatement = new BoundStatement(preparedStatement); | |
UUID uuid = UUID.randomUUID(); | |
boundStatement.bind(uuid, Arrays.asList("1", "2")); | |
session.execute(boundStatement); | |
preparedStatement = session.prepare("UPDATE t2 SET VALUE = ? WHERE id = ?"); | |
boundStatement = new BoundStatement(preparedStatement); | |
boundStatement.bind(Arrays.asList("9", "8"), uuid); | |
session.execute(boundStatement); | |
ResultSet resp = session.execute("SELECT * FROM t2"); | |
for (Row row : resp) | |
{ | |
System.out.println(row.getUUID("id").toString() + " " + row.getList("value", String.class)); | |
} | |
cluster.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment