{"id":25902,"date":"2014-05-30T22:00:51","date_gmt":"2014-05-30T19:00:51","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=25902"},"modified":"2014-05-30T13:23:24","modified_gmt":"2014-05-30T10:23:24","slug":"connecting-to-cassandra-from-java","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html","title":{"rendered":"Connecting to Cassandra from Java"},"content":{"rendered":"<p>In my post <a href=\"http:\/\/www.javacodegeeks.com\/2014\/05\/hello-cassandra.html\">Hello Cassandra<\/a>, I looked at downloading the Cassandra NoSQL database and using cqlsh to connect to a Cassandra database. In this post, I look at the basics of connecting to a Cassandra database from a Java client.<\/p>\n<p>Although there are <a href=\"http:\/\/brianoneill.blogspot.com\/2012\/08\/cassandra-apis-laundry-list.html\">several frameworks available<\/a> for <a href=\"http:\/\/stackoverflow.com\/questions\/18598745\/differences-betweeen-hector-cassandra-and-jdbc\">accessing the Cassandra database from Java<\/a>, I will use the <a href=\"http:\/\/planetcassandra.org\/client-drivers-tools\/\">DataStax Java Client JAR<\/a> in this post. The <a href=\"https:\/\/github.com\/datastax\/java-driver\">DataStax Java Driver for Apache Cassandra<\/a> is available <a href=\"https:\/\/github.com\/datastax\/java-driver\">on GitHub<\/a>. The <a href=\"https:\/\/github.com\/datastax\/java-driver\">datastax\/java-driver GitHub project page<\/a> states that it is a &#8220;Java client driver for Apache Cassandra&#8221; that &#8220;works exclusively with the Cassandra Query Language version 3 (<a href=\"http:\/\/www.bigdataplanet.info\/2013\/08\/How-to-use-Cassandra-CQL-in-your-Java-Application.html\">CQL3<\/a>)&#8221; and is &#8220;licensed under the <a href=\"http:\/\/www.apache.org\/licenses\/LICENSE-2.0\">Apache License, Version 2.0<\/a>.&#8221;<\/p>\n<p>&nbsp;<br \/>\nThe <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/java-driver\/whatsNew2.html\">Java Driver 2.0 for Apache Cassandra page<\/a> provides a <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/common\/drivers\/introduction\/introArchOverview_c.html\">high-level overview and architectural details<\/a> about the driver. Its <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/java-driver\/quick_start\/qsQuickstart_c.html\">Writing Your First Client section<\/a> provides code listings and explanations regarding <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/java-driver\/quick_start\/qsSimpleClientCreate_t.html\">connecting to Cassandra<\/a> with the Java driver and <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/java-driver\/quick_start\/qsSimpleClientAddSession_t.html\">executing CQL statements<\/a> from Java code. The code listings in this post are adaptations of those examples applied to my example cases.<\/p>\n<p>The <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/1.0\/common\/drivers\/introduction\/introArchOverview_c.html\">Cassandra Java Driver<\/a> has <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/1.0\/common\/drivers\/introduction\/driverDependencies_r.html\">several dependencies<\/a>. The <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/common\/drivers\/introduction\/introArchOverview_c.html\">Java Driver 2.0 for Apache Cassandra<\/a> <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/common\/drivers\/reference\/driverReference_r.html\">documentation<\/a> includes a page called <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/java-driver\/reference\/settingUpJavaProgEnv_r.html\">Setting up your Java development environment<\/a> that outlines the <a href=\"http:\/\/www.datastax.com\/documentation\/developer\/java-driver\/2.0\/java-driver\/reference\/settingUpJavaProgEnv_r.html?scroll=settingUpJavaProgEnv_r__dependencies-list\">Java Driver 2.0&#8217;s dependencies<\/a>: <a href=\"http:\/\/mvnrepository.com\/artifact\/com.datastax.cassandra\/cassandra-driver-core\/2.0.1\">cassandra-driver-core-2.0.1.jar<\/a> (<a href=\"https:\/\/github.com\/datastax\/java-driver\">datastax\/java-driver 2.0<\/a>), <a href=\"http:\/\/mvnrepository.com\/artifact\/io.netty\/netty\/3.9.0.Final\">netty-3.9.0-Final.jar<\/a> (<a href=\"http:\/\/netty.io\/\">netty<\/a> <a href=\"http:\/\/dl.bintray.com\/netty\/downloads\/netty-3.9.1.Final-dist.tar.bz2\">direct<\/a>), <a href=\"http:\/\/mvnrepository.com\/artifact\/com.google.guava\/guava\/16.0.1\">guava-16.0.1.jar<\/a> (<a href=\"https:\/\/code.google.com\/p\/guava-libraries\/wiki\/Release16\">Guava 16<\/a> <a href=\"http:\/\/search.maven.org\/remotecontent?filepath=com\/google\/guava\/guava\/16.0.1\/guava-16.0.1.jar\">direct<\/a>), <a href=\"http:\/\/mvnrepository.com\/artifact\/com.codahale.metrics\/metrics-core\/3.0.2\">metrics-core-3.0.2.jar<\/a> (<a href=\"http:\/\/metrics.codahale.com\/manual\/core\/\">Metrics Core<\/a>), and <a href=\"http:\/\/mvnrepository.com\/artifact\/org.slf4j\/slf4j-api\/1.7.5\">slf4j-api-1.7.5.jar<\/a> (<a href=\"http:\/\/www.slf4j.org\/\">slf4j<\/a> <a href=\"http:\/\/www.slf4j.org\/dist\/slf4j-1.7.5.tar.gz\">direct<\/a>). I also found that I needed to place <a href=\"https:\/\/github.com\/jpountz\/lz4-java\/blob\/master\/src\/java\/net\/jpountz\/lz4\/LZ4Factory.java\">LZ4Factory.java<\/a> and <a href=\"https:\/\/github.com\/xerial\/snappy-java\">snappy-java<\/a> on the classpath.<\/p>\n<p>The next code listing is of a simple class called <code>CassandraConnector<\/code>.<\/p>\n<h2>CassandraConnector.java<\/h2>\n<pre class=\" brush:java\">package com.marxmart.persistence;\r\n\r\nimport com.datastax.driver.core.Cluster;\r\nimport com.datastax.driver.core.Host;\r\nimport com.datastax.driver.core.Metadata;\r\nimport com.datastax.driver.core.Session;\r\n\r\nimport static java.lang.System.out;\r\n\r\n\/**\r\n * Class used for connecting to Cassandra database.\r\n *\/\r\npublic class CassandraConnector\r\n{\r\n   \/** Cassandra Cluster. *\/\r\n   private Cluster cluster;\r\n\r\n   \/** Cassandra Session. *\/\r\n   private Session session;\r\n\r\n   \/**\r\n    * Connect to Cassandra Cluster specified by provided node IP\r\n    * address and port number.\r\n    *\r\n    * @param node Cluster node IP address.\r\n    * @param port Port of cluster host.\r\n    *\/\r\n   public void connect(final String node, final int port)\r\n   {\r\n      this.cluster = Cluster.builder().addContactPoint(node).withPort(port).build();\r\n      final Metadata metadata = cluster.getMetadata();\r\n      out.printf(\"Connected to cluster: %s\\n\", metadata.getClusterName());\r\n      for (final Host host : metadata.getAllHosts())\r\n      {\r\n         out.printf(\"Datacenter: %s; Host: %s; Rack: %s\\n\",\r\n            host.getDatacenter(), host.getAddress(), host.getRack());\r\n      }\r\n      session = cluster.connect();\r\n   }\r\n\r\n   \/**\r\n    * Provide my Session.\r\n    *\r\n    * @return My session.\r\n    *\/\r\n   public Session getSession()\r\n   {\r\n      return this.session;\r\n   }\r\n\r\n   \/** Close cluster. *\/\r\n   public void close()\r\n   {\r\n      cluster.close();\r\n   }\r\n}<\/pre>\n<p>The above connecting class could be invoked as shown in the next code listing.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>Code Using CassandraConnector<\/h2>\n<pre class=\" brush:java\">\/**\r\n * Main function for demonstrating connecting to Cassandra with host and port.\r\n *\r\n * @param args Command-line arguments; first argument, if provided, is the\r\n *    host and second argument, if provided, is the port.\r\n *\/\r\npublic static void main(final String[] args)\r\n{\r\n   final CassandraConnector client = new CassandraConnector();\r\n   final String ipAddress = args.length &gt; 0 ? args[0] : \"localhost\";\r\n   final int port = args.length &gt; 1 ? Integer.parseInt(args[1]) : 9042;\r\n   out.println(\"Connecting to IP Address \" + ipAddress + \":\" + port + \"...\");\r\n   client.connect(ipAddress, port);\r\n   client.close();\r\n}<\/pre>\n<p>The example code in that last code listing specified default node and port of <code>localhost<\/code> and port <code>9042<\/code>. This port number is specified in the <a href=\"https:\/\/svn.apache.org\/repos\/asf\/cassandra\/trunk\/conf\/cassandra.yaml\">cassandra.yaml file<\/a> located in the <a href=\"http:\/\/www.datastax.com\/docs\/1.0\/configuration\/node_configuration\">apache-cassandra\/conf<\/a> directory. The <a href=\"http:\/\/www.datastax.com\/documentation\/cassandra\/1.2\/cassandra\/features\/featuresTOC.html\">Cassandra 1.2 documentation<\/a> has a page on <a href=\"http:\/\/www.datastax.com\/documentation\/cassandra\/1.2\/cassandra\/configuration\/configCassandra_yaml_r.html\">The cassandra.yaml configuration file<\/a> which describes the cassandra.yaml file as &#8220;the main configuration file for Cassandra.&#8221; Incidentally, another important configuration file in that same directory is <a href=\"http:\/\/svn.apache.org\/repos\/asf\/cassandra\/trunk\/conf\/cassandra-env.sh\">cassandra-env.sh<\/a>, which defines numerous JVM options for the <a href=\"http:\/\/stackoverflow.com\/questions\/2341866\/why-was-cassandra-written-in-java\">Java-based<\/a> Cassandra database.<\/p>\n<p>For the examples in this post, I will be using a MOVIES table created with the following Cassandra Query Language (CQL):<\/p>\n<h2>createMovie.cql<\/h2>\n<pre class=\" brush:sql\">CREATE TABLE movies\r\n(\r\n   title varchar,\r\n   year int,\r\n   description varchar,\r\n   mmpa_rating varchar,\r\n   dustin_rating varchar,\r\n   PRIMARY KEY (title, year)\r\n);<\/pre>\n<p>The above file can be executed within <a href=\"http:\/\/www.datastax.com\/documentation\/cql\/3.0\/cql\/cql_reference\/cqlsh.html\">cqlsh<\/a> with the command <code>source 'C:\\cassandra\\cql\\examples\\createMovie.cql'<\/code> (assuming that the file is placed in the specified directory, of course) and this is demonstrated in the next screen snapshot.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/05\/cassandraEnhancedMoviesTableCreated.png\"><img decoding=\"async\" class=\"aligncenter size-medium wp-image-25999\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/05\/cassandraEnhancedMoviesTableCreated-300x182.png\" alt=\"cassandraEnhancedMoviesTableCreated\" width=\"300\" height=\"182\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/05\/cassandraEnhancedMoviesTableCreated-300x182.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/05\/cassandraEnhancedMoviesTableCreated.png 677w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>One thing worth highlighting here is that the columns that were created as <code>varchar<\/code> <a href=\"http:\/\/www.datastax.com\/documentation\/cassandra\/1.2\/cassandra\/tools\/use_about_data_types_c.html\">datatypes<\/a> are described as <code>text<\/code> datatypes by the <a href=\"http:\/\/www.datastax.com\/docs\/1.1\/references\/cql\/DESCRIBE\">cqlsh describe command<\/a>. Although I created this table directly via <code>cqlsh<\/code>, I also could have created the table in Java as shown in the next code listing and associated screen snapshot that follows the code listing.<\/p>\n<h2>Creating Cassandra Table with Java Driver<\/h2>\n<pre class=\" brush:sql\">final String createMovieCql =\r\n     \"CREATE TABLE movies_keyspace.movies (title varchar, year int, description varchar, \"\r\n   + \"mmpa_rating varchar, dustin_rating varchar, PRIMARY KEY (title, year))\";\r\nclient.getSession().execute(createMovieCql);<\/pre>\n<p>The above code accesses an instance variable <code>client<\/code>. The class with this instance variable that it might exist in is shown next.<\/p>\n<h2>Shell of MoviePersistence.java<\/h2>\n<pre class=\" brush:java\">package dustin.examples.cassandra;\r\n\r\nimport com.datastax.driver.core.ResultSet;\r\nimport com.datastax.driver.core.Row;\r\n\r\nimport java.util.Optional;\r\n\r\nimport static java.lang.System.out;\r\n\r\n\/**\r\n * Handles movie persistence access.\r\n *\/\r\npublic class MoviePersistence\r\n{\r\n   private final CassandraConnector client = new CassandraConnector();\r\n\r\n   public MoviePersistence(final String newHost, final int newPort)\r\n   {\r\n      out.println(\"Connecting to IP Address \" + newHost + \":\" + newPort + \"...\");\r\n      client.connect(newHost, newPort);\r\n   }\r\n\r\n   \/**\r\n    * Close my underlying Cassandra connection.\r\n    *\/\r\n   private void close()\r\n   {\r\n      client.close();\r\n   }\r\n}<\/pre>\n<p>With the <code>MOVIES<\/code> table created as shown above (either by <code>cqlsh<\/code> or with Java client code), the next steps are to manipulate data related to this table. The next code listing shows a method that could be used to write new rows to the <code>MOVIES<\/code> table.<\/p>\n<pre class=\" brush:java wrap-lines:false\">\/**\r\n * Persist provided movie information.\r\n *\r\n * @param title Title of movie to be persisted.\r\n * @param year Year of movie to be persisted.\r\n * @param description Description of movie to be persisted.\r\n * @param mmpaRating MMPA rating.\r\n * @param dustinRating Dustin's rating.\r\n *\/\r\npublic void persistMovie(\r\n   final String title, final int year, final String description,\r\n   final String mmpaRating, final String dustinRating)\r\n{\r\n   client.getSession().execute(\r\n      \"INSERT INTO movies_keyspace.movies (title, year, description, mmpa_rating, dustin_rating) VALUES (?, ?, ?, ?, ?)\",\r\n      title, year, description, mmpaRating, dustinRating);\r\n}<\/pre>\n<p>With the data inserted into the <code>MOVIES<\/code> table, we need to be able to query it. The next code listing shows one potential implementation for querying a movie by title and year.<\/p>\n<h2>Querying with Cassandra Java Driver<\/h2>\n<pre class=\" brush:java\">\/**\r\n * Returns movie matching provided title and year.\r\n *\r\n * @param title Title of desired movie.\r\n * @param year Year of desired movie.\r\n * @return Desired movie if match is found; Optional.empty() if no match is found.\r\n *\/\r\npublic Optional&lt;Movie&gt; queryMovieByTitleAndYear(final String title, final int year)\r\n{\r\n   final ResultSet movieResults = client.getSession().execute(\r\n      \"SELECT * from movies_keyspace.movies WHERE title = ? AND year = ?\", title, year);\r\n   final Row movieRow = movieResults.one();\r\n   final Optional&lt;Movie&gt; movie =\r\n        movieRow != null\r\n      ? Optional.of(new Movie(\r\n           movieRow.getString(\"title\"),\r\n           movieRow.getInt(\"year\"),\r\n           movieRow.getString(\"description\"),\r\n           movieRow.getString(\"mmpa_rating\"),\r\n           movieRow.getString(\"dustin_rating\")))\r\n      : Optional.empty();\r\n   return movie;\r\n}<\/pre>\n<p>If we need to delete data already stored in the Cassandra database, this is easily accomplished as shown in the next code listing.<\/p>\n<h2>Deleting with Cassandra Java Driver<\/h2>\n<pre class=\" brush:java\">\/**\r\n * Deletes the movie with the provided title and release year.\r\n *\r\n * @param title Title of movie to be deleted.\r\n * @param year Year of release of movie to be deleted.\r\n *\/\r\npublic void deleteMovieWithTitleAndYear(final String title, final int year)\r\n{\r\n   final String deleteString = \"DELETE FROM movies_keyspace.movies WHERE title = ? and year = ?\";\r\n   client.getSession().execute(deleteString, title, year);\r\n}<\/pre>\n<p>As the examples in this blog post have shown, it&#8217;s easy to access Cassandra from Java applications using the Java Driver. It is worth noting that Cassandra is <a href=\"http:\/\/stackoverflow.com\/questions\/2341866\/why-was-cassandra-written-in-java\">written in Java<\/a>. The advantage of this for Java developers is that many of Cassandra&#8217;s configuration values are JVM options that Java developers are already familiar with. The <code>cassandra-env.sh<\/code> file in the Cassandra <code>conf<\/code> directory allows one to specify <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/technotes\/tools\/windows\/java.html#CBBIJCHG\">standard JVM options<\/a> used by Cassandra (such as heap sizing parameters <code>-Xms<\/code>, <code>-Xmx<\/code>, and <code>-Xmn<\/code>),<a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/tech\/vmoptions-jsp-140102.html\">HotSpot-specific JVM options<\/a> (such as <code>-XX:-HeapDumpOnOutOfMemoryError<\/code>, <code>-XX:HeapDumpPath<\/code>, <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/gc-tuning-6-140523.html\">garbage collection tuning options<\/a>, and <a href=\"http:\/\/stackoverflow.com\/questions\/1839599\/analyze-gc-logs-for-sun-hotspots-jvm-6\">garbage collection logging options<\/a>), <a href=\"http:\/\/docs.oracle.com\/cd\/E19683-01\/806-7930\/6jgp65ikq\/index.html\">enabling assertions<\/a> (<code>-ea<\/code>), and exposing Cassandra for <a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/jmx\/remote\/\">remote JMX management<\/a>.<\/p>\n<p>Speaking of Cassandra and JMX, Cassandra can be monitored via JMX as discussed in the &#8220;Monitoring using JConsole&#8221; section of <a href=\"http:\/\/www.datastax.com\/documentation\/cassandra\/2.0\/cassandra\/operations\/ops_monitoring_c.html\">Monitoring a Cassandra cluster<\/a>. The <a href=\"http:\/\/www.informit.com\/store\/practical-cassandra-a-developers-approach-9780321933942?w_ptgrevartcl=The+Basics+of+Monitoring+Cassandra_2169293\">book excerpt<\/a> <a href=\"http:\/\/www.informit.com\/articles\/article.aspx?p=2169293&amp;seqNum=2\">The Basics of Monitoring Cassandra<\/a> also discusses using JMX to monitor Cassandra. Because Java developers are more likely to be familiar with JMX clients such as <a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/management\/jconsole.html\">JConsole<\/a> and <a href=\"http:\/\/visualvm.java.net\/\">VisualVM<\/a>, this is an intuitive approach to monitoring Cassandra for Java developers.<\/p>\n<p>Another advantage of Cassandra&#8217;s Java roots is that Java classes used by Cassandra can be extended and Cassandra can be customized via Java. For example, <a href=\"http:\/\/cassandra.apache.org\/doc\/cql3\/CQL.html#types\">custom data types<\/a> can be implemented by <a href=\"http:\/\/cassandra-user-incubator-apache-org.3065146.n2.nabble.com\/Custom-data-type-is-not-work-at-C-2-0-td7590105.html\">extending the AbstractType class<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>The Cassandra Java Driver makes it easy to access Cassandra from Java applications. Cassandra also features significant Java-based configuration and monitoring and can even be customized with Java.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/marxsoftware.blogspot.com\/2014\/05\/connecting-to-cassandra-from-java.html\">Connecting to Cassandra from Java<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Dustin Marx at the <a href=\"http:\/\/marxsoftware.blogspot.com\/\">Inspired by Actual Events <\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In my post Hello Cassandra, I looked at downloading the Cassandra NoSQL database and using cqlsh to connect to a Cassandra database. In this post, I look at the basics of connecting to a Cassandra database from a Java client. Although there are several frameworks available for accessing the Cassandra database from Java, I will &hellip;<\/p>\n","protected":false},"author":122,"featured_media":53,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[111,113],"class_list":["post-25902","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-apache-cassandra","tag-nosql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Connecting to Cassandra from Java<\/title>\n<meta name=\"description\" content=\"In my post Hello Cassandra, I looked at downloading the Cassandra NoSQL database and using cqlsh to connect to a Cassandra database. In this post, I look\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Connecting to Cassandra from Java\" \/>\n<meta property=\"og:description\" content=\"In my post Hello Cassandra, I looked at downloading the Cassandra NoSQL database and using cqlsh to connect to a Cassandra database. In this post, I look\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-05-30T19:00:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-cassandra-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dustin Marx\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dustin Marx\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html\"},\"author\":{\"name\":\"Dustin Marx\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/945db7c24d37de80481570a5643f7958\"},\"headline\":\"Connecting to Cassandra from Java\",\"datePublished\":\"2014-05-30T19:00:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html\"},\"wordCount\":856,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-cassandra-logo.jpg\",\"keywords\":[\"Apache Cassandra\",\"NoSQL\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html\",\"name\":\"Connecting to Cassandra from Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-cassandra-logo.jpg\",\"datePublished\":\"2014-05-30T19:00:51+00:00\",\"description\":\"In my post Hello Cassandra, I looked at downloading the Cassandra NoSQL database and using cqlsh to connect to a Cassandra database. In this post, I look\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-cassandra-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-cassandra-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/05\\\/connecting-to-cassandra-from-java.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Connecting to Cassandra from Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/945db7c24d37de80481570a5643f7958\",\"name\":\"Dustin Marx\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a11cce21db49686299ad9afde297b5213759b39e79a54820195cf16b842639c0?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a11cce21db49686299ad9afde297b5213759b39e79a54820195cf16b842639c0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a11cce21db49686299ad9afde297b5213759b39e79a54820195cf16b842639c0?s=96&d=mm&r=g\",\"caption\":\"Dustin Marx\"},\"sameAs\":[\"http:\\\/\\\/marxsoftware.blogspot.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Dustin-Marx\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Connecting to Cassandra from Java","description":"In my post Hello Cassandra, I looked at downloading the Cassandra NoSQL database and using cqlsh to connect to a Cassandra database. In this post, I look","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html","og_locale":"en_US","og_type":"article","og_title":"Connecting to Cassandra from Java","og_description":"In my post Hello Cassandra, I looked at downloading the Cassandra NoSQL database and using cqlsh to connect to a Cassandra database. In this post, I look","og_url":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-05-30T19:00:51+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-cassandra-logo.jpg","type":"image\/jpeg"}],"author":"Dustin Marx","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Dustin Marx","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html"},"author":{"name":"Dustin Marx","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/945db7c24d37de80481570a5643f7958"},"headline":"Connecting to Cassandra from Java","datePublished":"2014-05-30T19:00:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html"},"wordCount":856,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-cassandra-logo.jpg","keywords":["Apache Cassandra","NoSQL"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html","url":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html","name":"Connecting to Cassandra from Java","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-cassandra-logo.jpg","datePublished":"2014-05-30T19:00:51+00:00","description":"In my post Hello Cassandra, I looked at downloading the Cassandra NoSQL database and using cqlsh to connect to a Cassandra database. In this post, I look","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-cassandra-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-cassandra-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/05\/connecting-to-cassandra-from-java.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Connecting to Cassandra from Java"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/945db7c24d37de80481570a5643f7958","name":"Dustin Marx","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a11cce21db49686299ad9afde297b5213759b39e79a54820195cf16b842639c0?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a11cce21db49686299ad9afde297b5213759b39e79a54820195cf16b842639c0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a11cce21db49686299ad9afde297b5213759b39e79a54820195cf16b842639c0?s=96&d=mm&r=g","caption":"Dustin Marx"},"sameAs":["http:\/\/marxsoftware.blogspot.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Dustin-Marx"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/25902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/122"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=25902"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/25902\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/53"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=25902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=25902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=25902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}