SonicBase. In-memory embedded, standalone or distributed sql database

Tutorial - Standalone Deploy


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

Install Java

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.

    Run Init Script

    In the client, type:
      run script init-tables.command

    This will start the cluster, create the database and create some tables. This script contains the following commands:
    
    start cluster
    create database db
    create table Employers (id VARCHAR(64), name VARCHAR(256))
    create index employerId on Employers(id)
    create table Persons (id1 BIGINT, id2 BIGINT, name VARCHAR(256), socialSecurityNumber VARCHAR(20), relatives VARCHAR(64000), restricted BOOLEAN, gender VARCHAR(8), PRIMARY KEY (id1))
    create table Memberships (personId BIGINT, personId2 BIGINT, membershipName VARCHAR(20), resortId BIGINT, PRIMARY KEY (personId, personId2))
    create table Resorts (resortId BIGINT, resortName VARCHAR(20), PRIMARY KEY (resortId))
        

    Insert Record

    In the client, type:
      insert into persons (id1, name, socialsecuritynumber) VALUES (100, 'bob', '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.getString("socialsecuritynumber"));
        }
      }
    }

    Stop Cluster

    In the client, type:
      stop cluster