The SQream JDBC Connector - Overview

  • This guide describes the implementation of the SQream JDBC connector and is designed for SQream DB administrators and developers.

  • The code sample shows how to initialize a connection, insert data to a table and run SQL queries (statements).

  • SQream connector protocol version: 6

1. API Reference

See the JAVA 8 JDBC reference

https://docs.oracle.com/javase/8/docs/api/java/sql/package-summary.html

2. Installation Instructions

Place the JAR file in the CLASSPATH. You will need the following JAR file:

SqreamJDBC.jar

3. Code Samples

3.1. Connecting to sqream, creating a table with some data and retrieveing the data

Example
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;


public class SampleTest {

    // Replace with your respective URL
    static final String url = "jdbc:Sqream://127.0.0.1:5000/master;user=sqream;password=sqream;cluster=false;ssl=false";

    Connection conn  = null;
    Statement stmt = null;
    ResultSet rs = null;
    DatabaseMetaData dbmeta = null;

    int res = 0;

    public void testJDBC() throws SQLException, IOException {

        conn = DriverManager.getConnection(url,"sqream","sqream");

        // Create a table
        String sql = "create or replace table test (x int)";
        stmt = conn.createStatement();
        stmt.execute(sql);
        stmt.close();

        // Insert some valuess
        sql = "insert into test values (5),(6)";
        stmt = conn.createStatement();
        stmt.execute(sql);
        stmt.close();

        // Retrieve
        sql = "select * from test";
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        while(rs.next()) {
            res = rs.getInt(1);
            System.out.println(res);
        }
        rs.close();
        stmt.close();

        // Get table metadata
        dbmeta = conn.getMetaData();
        rs = dbmeta.getTables("master", "public", "test" ,new String[] {"TABLE"} );
        while (rs.next()) {

            ResultSet rs2 = dbmeta.getColumns(null, null, "test", null);
            while (rs2.next()) {
                System.out.println(rs2.getString(1));
            }
            rs2.close();
        }
        rs.close();
        conn.close();
    }


    public static void main(String[] args) throws SQLException, KeyManagementException, NoSuchAlgorithmException, IOException, ClassNotFoundException{

        // Load JDBC driver - not needed with newer version
        Class.forName("com.sqream.jdbc.SQDriver");

        SampleTest test = new SampleTest();
        test.testJDBC();
    }
}

Copyright © 2010-2018. All rights reserved.

This document is provided for information purposes only and the contents hereof are subject to change without notice. This document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied in law, including implied warranties and conditions of merchant- ability or fitness for a particular purpose.

We specifically disclaim any liability with respect to this document and no contractual obligations are formed either directly or indirectly by this document.

This document may not be reproduced in any form, for any purpose, without our prior written permission.