Created
May 4, 2015 03:01
-
-
Save nobusue/1c9d51a6675d7aa5359d to your computer and use it in GitHub Desktop.
Cassandra Java Driverでデータのinsertとselectを行う
This file contains hidden or 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
@Grapes( | |
@Grab(group='com.datastax.cassandra', module='cassandra-driver-core', version='2.1.5') | |
) | |
import com.datastax.driver.core.* | |
def cluster = Cluster.builder().addContactPoint('127.0.0.1').build() | |
def session = cluster.connect() | |
session.execute("INSERT INTO first_keyspace.first_table (name, value) VALUES ('foo', 'bar');"); | |
session.execute("INSERT INTO first_keyspace.first_table (name, value) VALUES ('gee', 'baz');"); | |
def resultSet = session.execute("select * from first_keyspace.first_table where name = 'gee';") | |
resultSet.each { | |
println it.getColumnDefinitions() | |
println it | |
} | |
session.close() | |
cluster.close() |
def statement = session.prepare("INSERT INTO first_keyspace.first_table (name, value) VALUES ('foo', 'bar');")
statement.setConsistencyLevel(ConsistencyLevel.QUORUM)
session.execute(statement)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コンテステンシーレベルを指定する場合は、
Session#prepare(String)
PreparedStatement#setConsistencyLevel(ConsistencyLevel)
を使う感じでしょうか。