Tutorial - Local Deploy


In this tutorial we will walk you through the process of starting a cluster and inserting into and reading from it.

Download The Software

Unpack Package

  • Linux/Mac: Type "tar -xzf sonicbase-<version>.tgz" in the parent directory where you want the software to go. A directory named "sonicbase" will be created.
  • Windows: Unzip the file sonicbase-<version>.zip in the parent directory where you want the software to go. A directory named "sonicbase" will be created.
  • Start Admin Client

    Change to the sonicbase/bin directory and type "./cli" for MacOS and Linux and "./cli.bat" for cygwin and "cli.bat" for Windows. This will start the SonicBase admin client.

    Use Cluster

    In the client, type:
      use cluster 1-local

    Start Cluster

    In the client, type:
      start cluster

    This will start the cluster on the local machine.

    Create Database

    In the client, type:
      create database db

    This will create the database named "db".

    Create Table

    In the client, type:
      create table persons (name VARCHAR, age INTEGER, ssn VARCHAR, PRIMARY KEY (ssn))

    Insert Record

    In the client, type:
      insert into persons (name, age, ssn) VALUES ('bob', 22, '555-66-7777')

    Read Record

    In the client, type:
      select * from persons

    You should see the inserted record displayed in the client.

    Access From JDBC Driver


    Create and run the following class:

    
    package foo;
    
    public class Tutorial {
      public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.sonicbase.jdbcdriver.Driver");
        try (Connection conn = DriverManager.getConnection("jdbc:sonicbase:127.0.0.1:9010/db");
             PreparedStatement stmt = conn.prepareStatement("select * from persons");
             ResultSet rs = stmt.executeQuery()) {
          rs.next();
          System.out.println(rs.getString("name") + " " + rs.getInt("age") + " " + rs.getString("ssn"));
        }
      }
    }

    Stop Cluster

    In the client, type:
      stop cluster