Database Reference
In-Depth Information
Setup and Inserting Data
We'll look at inserts first, because you need to have something in the database to query. In this
section we set up a Java project and walk through a complete example that does an insert and
then reads the data back.
First, download Cassandra from http://cassandra.apache.org . It's easiest to get started with the
binary version. See Chapter 2 if you're having any trouble.
Now let's create a new project to test some of our work. For now, we'll use a Java project in
Eclipse. First, create a new project, and then add a few JARs to your classpath: a Log4J JAR to
output log statements (don't forget to set the properties file for your own classes); the Thrift lib-
rary called libthrift-r917130.jar, which contains the org.apache.thrift classes; and the Cassandra
JAR apache-cassandra-x.x.x.jar, which contains the org.apache.cassandra classes. We also need
to add the SLF4J logger (both the API and the implementation JAR), which Cassandra requires.
Finally, add an argument to your JVM to add the log4j.propertiesile to your classpath:
-Dlog4j.configuration=file:///home/eben/books/cassandra/log4j.properties
NOTE
In Eclipse, you can add the log4j.propertiesile by creating a new Run Configuration. Click the Argu-
ments tab, and then in the VM Arguments text field, enter the parameter specified in the previous code
sampleā€”of course using the actual path to your properties file.
My log4j.propertiesile looks like this:
# output messages into a rolling log file as well as stdout
log4j.rootLogger=DEBUG,stdout,R
# stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n
# rolling log file
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=5MB
log4j.appender.file.maxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %C %F (line %L) %m%n
# This points to your logs directory
log4j.appender.R.File=cass-client.log
Search WWH ::




Custom Search