Skip to navigation

JDBC Manual

View as Markdown

The Ocient® JDBC Driver and command-line interface (CLI) enable you to connect to Ocient using a JDBC connection. Ensure that you meet the prerequisites before using the Ocient JDBC Driver. Then, invoke the CLI program, configure options, and connect to a database using the driver.

You can also use the data extract tool to extract a result set to delimited files in the target location. For details about data extracting, see Data Extract Tool.

For a list of commands available in the JDBC CLI, see Commands Supported by the Ocient JDBC CLI Program.

Prerequisites

This software is required for the JDBC driver.

SoftwareVersion
OcientUse the latest Ocient System version.
Operating System (OS)Windows®, Linux®, or macOS®.
Use the latest version of each OS.
Java®See the Version Compatibility.

Driver Features

The Ocient JDBC connector supports these features as of the current version.

Unicode SupportUTF-8
Isolation LevelsOcient does not support transactions at this time.
Data TypesSupports all Ocient Data Types.
Security / EncryptionUses SSL/TLS to connect to the Ocient System.
TLS protocol is available as a JDBC Configuration Option.

Invoke the Ocient JDBC CLI Program

If your system meets all the necessary prerequisites, you can run the JDBC CLI by using the Ocient JDBC JAR file. To do this, follow these steps.

1

Go to the Ocient Apache® Maven™ repository for all JDBC versions. For more information on which version to pick, see the Version Compatibility page.

2

For the JDBC version you want to use, download the JAR file with dependencies. This JAR file follows the format: ocient-jdbc4-<version number>-jar-with-dependencies.jar.

Move this JAR file to the directory where your Ocient System is installed.

3

From the shell terminal, run this command to launch the JDBC CLI.

java -classpath <path_to_jar_with_dependencies> com.ocient.cli.CLI [<username> [<password>]]

This example runs JDBC version 2.10.

java -classpath ./ocient-jdbc4-2.10-jar-with-dependencies.jar com.ocient.cli.CLI testuser testpassword
4

After launching, the JDBC CLI prompts you to enter your username and password.

Username: admin@system
Password: admin

The interface changes to the Ocient CLI.

Ocient> _
5

Connect to your system from the JDBC using a connection string.

Assuming the standard port 4050, a self-signed certificate, and the SQL Node IP address 10.10.1.1, you can connect to the system database with the following connecting string.

Ocient> connect to jdbc:ocient://10.10.1.1:4050/system;

The CLI responds with a connection message.

Connected to jdbc:ocient://10.10.1.1:4050/system
Ocient> _

Now that you are connected to your system, you can execute any queries or commands.

For Java version 1.8.0_144, download and install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 8.

JDBC CLI Configuration Options

The JDBC CLI reads a configuration file consisting of key-value pairs located at ~/.ocient-cli-configuration with this format.

key1=value1
key2=value2
...
keyN=valueN

The JDBC CLI supports these options.

OptionDescriptionDefault Value
cliIdleTimeoutMinutesConfigures the idle timeout for the CLI. The CLI rejects subsequent commands and exits the process after cliIdleTimeoutMinutes minutes of inactivity.0 if left unspecified or the configuration file does not exist.
printUuidAccepts values on or off.
If you set the printUuid option to on, the system prints the query identifier for each query that you execute in the CLI.
off

For supported commands, see Commands Supported by the Ocient JDBC CLI Program.

Use the Ocient JDBC Driver in Java Programs

First, you must load the Ocient driver class with this statement in a Java program using the JDBC driver.

Class.forName("com.ocient.jdbc.JDBCDriver");

The driver class is located in the JDBC driver JAR file named ocient-jdbc4.jar and must be available in the CLASSPATH defined for the program.

Connect Using JDBC

The Ocient JDBC driver supports connection properties that can be supplied using the CONNECT command in the JDBC CLI or as a properties object passed in a Java application.

JDBC URL Example

This connection string includes various connection properties that trail the login credentials.

CONNECT TO 'jdbc:ocient://db.example.com:6432/salesdb;user=admin@system;password=admin;logLevel=INFO;networkTimeout=15000;enableBulkLoad=true;bulkLoadThreshold=50000';

Java DriverManager Example

Alternatively, you can use the DriverManager class to provide connection properties if you are using a JDBC connection as part of a Java application.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class OcientConnectionExample {
public static void main(String[] args) throws SQLException {
// Base JDBC URL: host, port, and database
String url = "jdbc:ocient://db.example.com:6432/salesdb";
// JDBC connection properties
Properties props = new Properties();
props.setProperty("user", "analytics_user"); // Ocient username
props.setProperty("password", "StrongPassw0rd!"); // Ocient password
props.setProperty("logLevel", "INFO"); // Driver logging verbosity
props.setProperty("networkTimeout", "15000"); // 15s network timeout (ms)
props.setProperty("enableBulkLoad", "true"); // Use bulk load for large batches
props.setProperty("bulkLoadThreshold", "50000"); // Min rows for bulk loa
try (Connection conn = DriverManager.getConnection(url, props)) {
}
}
}

Supported JDBC Connection Properties

The JDBC driver supports these connection parameters.

ParameterDescription
bulkLoadChunkSizeThe number of rows to include in each JSON data file (chunk) uploaded. The default value is 60000.
bulkLoadCleanupOnFailureIf you set this parameter value to true, the driver deletes the temporary files and pipelines even if the load fails. The default value is true.
bulkLoadFailOnErrorIf you set this parameter value to true, executeBatch() fails if any INSERT operation fails.

If you set this parameter value to false, executeBatch() falls back to a standard multi-row INSERT operation if any INSERT operation fails. The default value is false.
bulkLoadPollIntervalSecondsThe number of seconds to wait between polling the sys.pipelines system catalog table for load status. The default value is 2.
bulkLoadSshKeyPathThe absolute path to the password-less private SSH key file. The default value is ~/.ssh/id_rsa.
bulkLoadSshUserThe SSH username to use when connecting to Loader Nodes.
bulkLoadThresholdThe minimum number of rows in a batch group to trigger a bulk load. The default value is 25000.
defaultSchemaDefault schema.
enableBulkLoadEnables the high-speed bulk load feature. Set this parameter value to true to enable this feature. Otherwise, set this parameter to false to leave the feature disabled. The default value is false.
forceIf set to true (case-sensitive), this parameter disables load-balancing for the connection.
handshakeSpecifies the handshake protocol used for the connection.
Supported options include: "CBC", "GCM", "SSO"
"GCM" — (Galois/Counter Mode). This is the default encryption and is the recommended password encryption algorithm.
"CBC" — (Cipher Block Chaining) for password encryption.
"SSO" — Single Sign-On.
identityproviderAn SSO integration established in the database. For details, see Cluster and Node Management.
logfileThe filename to use for JDBC tracing.
loglevelIf set to ERROR (warnings and errors only) or DEBUG (verbose tracing) and logfile is also set, JDBC tracing is enabled. This parameter is case-sensitive.
longQueryThresholdEstimated query runtime in milliseconds before deeper query optimization runs.
0 — Use database server default.
-1 — Never run deeper optimization.
maxRowsMaximum allowed result set size in the number of rows.
maxTempDiskMaximum allowed temp disk usage as a percentage (0 - 100).
maxThreadsPerResultSetThe maximum number of threads the client uses to fetch rows from the server per Result Set, as defined in the official JDBC documentation. In this context, a thread represents a logical connection to the database.
Applications that create and operate on Statement objects concurrently might find value in setting this property. Defaults to 0, which effectively creates an unbounded Result Set thread pool.
maxTimeMaximum allowed runtime of a query in seconds before it is canceled on the server.
networkTimeoutNetwork connection timeout in milliseconds.
If unspecified, this defaults to 10000 milliseconds.
parallelismLimits a query to running on a specified number of cores on each CPU.
passwordThe password for the user.
priorityQuery priority. This sets the priority for queries to run on the server side.
If unspecified, this defaults to 1.0.
priorityAdjustFactorThe default query priority adjustment value. For details, see Commands Supported by the Ocient JDBC CLI Program.
priorityAdjustTimeThe default frequency to adjust the query priority. For details, see Commands Supported by the Ocient JDBC CLI Program.
serviceClassNameSpecifies the name of the service class to use for the database session.
sparkModeWhen you set this parameter to true, the driver enables Apache® Spark™‑specific JDBC behavior intended to improve compatibility with the Ocient Spark connector. For details, see JDBC Spark Connector.

This parameter defaults to false if you are connecting directly using the Ocient JDBC driver (e.g., connecting with the DriverManager class or CLI). Otherwise, if you are using the Spark connector (catalog or .format("ocient")), the default is true.
ssoNumericAddressSpecifies the SSO callback URL as 127.0.0.1. When this value is false, the URL is localhost. The default value is false.
ssoOAuthCodeCallbackPortIf ssoOAuthFlow=authorizationCode, this property specifies the port that the SSO authorization uses.
If unspecified, the default value is 7050.
ssoOAuthFlowThis property is only applicable if SSO authorization is enabled.
Forces the driver to use either the “authorizationCode” or “deviceGrant” flow to establish a Single Sign-On session.
If this property is not provided, the Ocient® System uses the “authorizationCode” flow when a web browser is available to the client and the “deviceGrant” flow when a web browser is not available to the client.
ssoDebugModeWhen set to true, the system records additional log messages related to SSO.
ssoOktaNativeTokenPathThe path to the OKTA® Native Token (AES-256GCM JWE). The path is relative to your home directory (i.e. ’~/’).
ssoSslCallbackSpecifies whether to use HTTPS instead of HTTP for the SSO callback URL. The default value is false.
ssoTimeoutSecondsThe number of seconds before the SSO connection request times out. The default value is 60.
statementPoolingℹ️ This property has been removed as of Ocient JDBC version 2.104 and later.
When set to ON, recently used statements are cached.
Set to OFF when using a third-party application that implements statement pooling
tlsCan be set to unverified or on. Enables SSL/TLS encryption for the connection.
timeoutMillisNumber of milliseconds before cancellable operations are timed out and killed by the driver. 0 means no timeout. Default: 0
userThe identifier of the user.

JDBC Bulk Loading

For very large batches, the Ocient JDBC driver provides a high-speed bulk load path. When you enable bulk loading, the driver bypasses the standard multi-row insert operation and instead streams the batch data directly to the Loader Nodes in the cluster using SSH/SFTP. The data loads in the in-memory JSON Lines format using a temporary, system-generated Ocient pipeline, providing a massive performance boost for large-scale data ingestion.

Configuration

Follow these steps to configure bulk loading in your JDBC driver.

SSH Key Access and Node

JDBC bulk loading does not use password authentication. Instead, you must use SSH access for all Loader Nodes in the cluster.

To point the driver to your private SSH key file, use the bulkLoadSshKeyPath JDBC connection property. The client application must be able to read this file.

The driver automatically discovers available Loader Nodes by querying the sys.nodes and sys.service_roles system catalog tables.

Data Type Mapping

The JDBC driver supports all standard scalar types.

For complex types, Java SQL STRUCT (java.sql.Struct) types load as Ocient TUPLE types, and Java ARRAY (java.sql.Array) types load as Ocient ARRAY types.

Enable Bulk Loading

The JDBC driver disables bulk loading by default. To enable it, you must meet these conditions:

  • Set the enableBulkLoad connection property to true.
  • Use a parameterized INSERT statement that uses placeholders for values, e.g., INSERT INTO customers (id, name, status) VALUES (?, ?, ?). For details, see Set Up Parameterized Insert Statements.
  • The total number of rows in the batch group meets or exceeds the bulkLoadThreshold property.

For recommended configuration settings for Spark workloads, see Bulk Loading Best Practices.

Set Up Parameterized INSERT Statements

These steps demonstrate how to use a single parameterized INSERT statement using the Java PreparedStatement class. The parameterized statement binds different values for each row.

1

Create the PreparedStatement object ps with ? placeholders.

String sql = "INSERT INTO customers (id, name, status) VALUES (?, ?, ?)";
PreparedStatement ps = conn.prepareStatement(sql);
2

Bind parameter values by position.

ps.setLong(1, 123L); // First ?
ps.setString(2, "Alice"); // Second ?
ps.setString(3, "ACTIVE"); // Third ?
3

Execute a single insert.

ps.executeUpdate();

Or, add multiple rows as a batch.

// First row
ps.setLong(1, 123L);
ps.setString(2, "Alice");
ps.setString(3, "ACTIVE");
ps.addBatch();
// Second row
ps.setLong(1, 124L);
ps.setString(2, "Bob");
ps.setString(3, "INACTIVE");
ps.addBatch();
// Send them together
int[] results = ps.executeBatch();
4

Close the resources.

ps.close();

Connection Encryption (SSL/TLS)

The JDBC driver can use SSL/TLS to connect to Ocient, causing all traffic to be encrypted. Specify the tls property on the connect statement to enable TLS support. The tls property supports these values.

unverified Traffic on the connection is encrypted, but no verification is done on the certificate received from the Ocient System.

on Traffic is encrypted, and the JDBC client must be able to verify the certificate received from the Ocient System.

The TLS on mode requires that the client knows the Certificate Authority that signed the certificate provided by the Ocient System. Typically, this mode requires either that the certificate is signed by a well-known certificate authority, or the Certificate Authority certificate has been imported into the truststore of the Java system. The Java keytool utility is used to manipulate a Java truststore.

Secure Connections Using TLS discusses how you can configure user-defined certificates for the Ocient System.

Sample Java Program Using the Ocient JDBC Driver

This sample program demonstrates how to utilize the Ocient JDBC driver to establish a connection to a database, construct a prepared SQL statement, execute the query, and iterate through the result set.

public class OcientJDBCExample {
public static void main(final String args[]) {
Class.forName("com.ocient.jdbc.JDBCDriver");
Properties props = new Properties();
props.setProperty("user", "username");
props.setProperty("password", "pwd");
props.setProperty("force", "true");
String url = "jdbc:ocient://192.168.121.82:4050/db";
Connection conn = DriverManager.getConnection(url, props);
PreparedStatement pstmt = conn.prepareStatement(
"select l_orderkey from tpch.lineitem where l_linenumber = ?");
Pstmt.setInt(1, 4);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
// do something with row
}
rs.close();
pstmt.close();
conn.close();
return;
}
}

For supported classes and methods, see JDBC Classes and Methods.

Related Links

Connect Using JDBC

Data Extract Tool

Commands Supported by the Ocient JDBC CLI Program

JDBC Classes and Methods.


**Linux®is the registered trademark of Linus Torvalds in the U.S. and other countries.