Created
June 23, 2015 19:05
-
-
Save tlberglund/abeb13a0da4c153622b3 to your computer and use it in GitHub Desktop.
Java Driver Talk at DC C* Day
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.UUID; | |
import java.util.Date; | |
public class Cassandra { | |
Cluster cluster; | |
Session session; | |
PreparedStatement smt; | |
public void setup() { | |
cluster = Cluster.builder().addContactPoint("127.0.0.1").build(); | |
session = cluster.connect("killrvideo"); | |
} | |
public void prepareStatement() { | |
smt = session.prepare("INSERT INTO users (userid, created_date, email, firstname, lastname) VALUES (?,?,?,?,?);"); | |
} | |
public void insert(String firstName, String lastName, String email) { | |
BoundStatement bs = new BoundStatement(smt); | |
session.execute(bs.bind(UUID.randomUUID(), new Date(), firstName, lastName, email)); | |
} | |
public static void main(String args[]) | |
{ | |
Cassandra c = new Cassandra(); | |
c.setup(); | |
c.prepareStatement(); | |
c.insert("Tim", "Berglund", "tim.berglund@datastax.com"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment