title: how to create a keyspace in cassandra?
body: <p>i'm using a snippet to understand cassandra and syntax:</p>
  
  <pre><code>import com.datastax.driver.core.Cluster;
  import com.datastax.driver.core.ResultSet;
  import com.datastax.driver.core.Row;
  import com.datastax.driver.core.Session;
  
  public class App {
  
      public static void main(String[] args) {
  
          Cluster cluster;
          Session session;
  
          // Connect to the cluster and key space "demo"
          cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
          session = cluster.connect("demo");
  
          // Insert one record into the users table
          session.execute("INSERT INTO users (lastname, age, city, email, firstname) VALUES ('Jones', 35, 'Austin', 'bob@example.com', 'Bob')");
  
          // Use select to get the user we just entered
          ResultSet results = session.execute("SELECT * FROM users WHERE lastname='Jones'");
          for (Row row : results) {
              System.out.format("%s %d\n", row.getString("firstname"), row.getInt("age"));
          }
  
          // Update the same user with a new age
          session.execute("update users set age = 36 where lastname = 'Jones'");
  
          // Select and show the change
          results = session.execute("select * from users where lastname='Jones'");
          for (Row row : results) {
              System.out.format("%s %d\n", row.getString("firstname"), row.getInt("age"));
          }
  
          // Delete the user from the users table
          session.execute("DELETE FROM users WHERE lastname = 'Jones'");
  
          // Show that the user is gone
          results = session.execute("SELECT * FROM users");
          for (Row row : results) {
              System.out.format("%s %d %s %s %s\n", row.getString("lastname"), row.getInt("age"), row.getString("city"),
                      row.getString("email"), row.getString("firstname"));
          }
  
          // Clean up the connection by closing it
          cluster.close();
      }
  }
  </code></pre>
  
  <p>On execution i get this error:</p>
  
  <pre><code>log4j:WARN No appenders could be found for logger (com.datastax.driver.core.SystemProperties).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  Exception in thread "main" com.datastax.driver.core.exceptions.InvalidQueryException: Keyspace 'demo' does not exist
      at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
      at com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:289)
      at com.datastax.driver.core.Cluster.connect(Cluster.java:287)
      at org.sparkexamples.cassandraExample.main.App.main(App.java:17)
  Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Keyspace 'demo' does not exist
      at com.datastax.driver.core.Responses$Error.asException(Responses.java:103)
      at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:140)
      at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:293)
      at com.datastax.driver.core.RequestHandler.onSet(RequestHandler.java:455)
      at com.datastax.driver.core.Connection$Dispatcher.messageReceived(Connection.java:734)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
      at org.jboss.netty.handler.timeout.IdleStateAwareChannelUpstreamHandler.handleUpstream(IdleStateAwareChannelUpstreamHandler.java:36)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
      at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
      at org.jboss.netty.handler.timeout.IdleStateHandler.messageReceived(IdleStateHandler.java:294)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
      at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
      at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
      at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:70)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
      at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
      at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
      at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
      at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)
      at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
      at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
      at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
      at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
      at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
      at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
      at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
      at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
      at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
      at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>In addiction, i configured everything with spark (maven/libs), but i don't know  how to create a keyspace using java code?</p>
  
  <p>thanks in advance.</p>