JDBC¶
The BLUE JDBC driver lets you connect to BLUE using many Java applications and tools.
Before You Begin¶
The BLUE JDBC driver requires Java 1.8 or newer
Download the BLUE JDBC driver here
We recommend using Oracle Java or OpenJDK
Connection String¶
JDBC drivers rely on a connection string.
URL Template:
jdbc:Sqream://{host}:{port}/{database};accessToken=<YourToken>;[<optional parameters>; ...]
JDBC driver class name:
com.sqream.jdbc.BlueDriver
Connection Parameters¶
The following table shows the connection string parameters:
Item |
State |
Default |
Description |
---|---|---|---|
|
Mandatory |
None |
FQDN and port of the Blue cluster. For example, |
|
Mandatory |
None |
Database name to connect to. For example, |
|
Mandatory |
None |
A BLUE client access token |
|
Optional |
|
Enables on-demand loading, and defines double buffer size for the result. The |
|
Optional |
|
Defines the bytes size for inserting a buffer before flushing data to the server. Clients running a parameterized insert (network insert) can define the amount of data to collect before flushing the buffer |
|
Optional |
|
Defines the logger level as either |
|
Optional |
|
Enables the file appender and defines the file name. The file name can be set as either the file name or the file path |
Sample Java Program¶
You can download the JDBC Application Sample File
1import java.sql.Connection;
2import java.sql.DatabaseMetaData;
3import java.sql.DriverManager;
4import java.sql.Statement;
5import java.sql.ResultSet;
6
7import java.io.IOException;
8import java.security.KeyManagementException;
9import java.security.NoSuchAlgorithmException;
10import java.sql.SQLException;
11
12
13
14public class SampleTest {
15
16 // Replace with your connection string
17 static final String url = "jdbc:Sqream://blue_cluster:443/master;accessToken=######################";
18
19 // Allocate objects for result set and metadata
20 Connection conn = null;
21 Statement stmt = null;
22 ResultSet rs = null;
23 DatabaseMetaData dbmeta = null;
24
25 int res = 0;
26
27 public void testJDBC() throws SQLException, IOException {
28
29 // Create a connection
30 conn = DriverManager.getConnection(url);
31
32 // Create a table with a single integer column
33 String sql = "CREATE TABLE test (x INT)";
34 stmt = conn.createStatement(); // Prepare the statement
35 stmt.execute(sql); // Execute the statement
36 stmt.close(); // Close the statement handle
37
38 // Insert some values into the newly created table
39 sql = "INSERT INTO test VALUES (5),(6)";
40 stmt = conn.createStatement();
41 stmt.execute(sql);
42 stmt.close();
43
44 // Get values from the table
45 sql = "SELECT * FROM test";
46 stmt = conn.createStatement();
47 rs = stmt.executeQuery(sql);
48 // Fetch all results one-by-one
49 while(rs.next()) {
50 res = rs.getInt(1);
51 System.out.println(res); // Print results to screen
52 }
53 rs.close(); // Close the result set
54 stmt.close(); // Close the statement handle
55 }
56
57
58 public static void main(String[] args) throws SQLException, KeyManagementException, NoSuchAlgorithmException, IOException, ClassNotFoundException{
59
60 // Load Blue JDBC driver
61 Class.forName("com.sqream.jdbc.BlueDriver");
62
63 // Create test object and run
64 SampleTest test = new SampleTest();
65 test.testJDBC();
66 }
67}