GridGain Developers Hub

JDBC Driver

GridGain is shipped with JDBC driver that allows processing of distributed data using standard SQL statements like SELECT, INSERT, UPDATE, or DELETE directly from the JDBC side. The name of the driver’s class is org.apache.ignite.jdbc.IgniteJdbcDriver.

This implementation of JDBC driver does not support the following functionality:

  • SSL/TLS connection;

  • Multiple Endpoints;

  • Multi-statement requests;

  • CREATE TABLE, ALTER TABLE, WITH, and MERGE commands.

Setting Up

JDBC driver uses the client connector to work with the cluster. For more information on configuring client connector, see Client Connector Configuration.

The JDBC connector needs to be included from Maven:

<dependency>
    <groupId>org.gridgain</groupId>
    <artifactId>ignite-jdbc</artifactId>
    <version>9.0.0</version>
</dependency>

Here is how you can open a JDBC connection to the cluster node listening on IP address 127.0.0.1:

Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800");

The driver connects to one of the cluster nodes and forwards all the queries to it for final execution. The node handles the query distribution and the result’s aggregations. Then the result is sent back to the client application.

The JDBC connection string can have an optional list of name-value pairs as parameters after the '?' delimiter. Name and value are separated by the '=' symbol and multiple properties are separated either by an '&' or a ';'. Separate sign can’t be mixed and should be either semicolon or ampersand sign.

jdbc:ignite:thin://host[:port][,host[:port][/schema][[?parameter1=value1][&parameter2=value2],...]]
jdbc:ignite:thin://host[:port][,host[:port][/schema][[?parameter1=value1][;parameter2=value2],...]]
  • host is required and defines the host of the cluster node to connect to.

  • port is the port to use to open the connection. 10800 is used by default if this parameter is omitted.

  • schema is the schema name to access. PUBLIC is used by default. This name should correspond to the SQL ANSI-99 standard. Non-quoted identifiers are not case sensitive. Quoted identifiers are case sensitive. When semicolon format is used, the schema may be defined as a parameter with name schema.

  • parameters are optional parameters. The following parameters are available:

    • connectionTimeZone - Client connection time-zone ID. This property can be used by the client to change the time zone of the session on the server. Affects the interpretation of dates in queries that do not specify the time zone explicitly. If not set, system default on client timezone will be used.

    • queryTimeout - Number of seconds the driver will wait for a Statement object to execute. 0 means there is no limit. Default value: 0.

    • connectionTimeout - Number of milliseconds JDBC client will wait for server to respond. 0 means there is no limit. Default value: 0.

    • reconnectThrottlingPeriod - Reconnect throttling period, in milliseconds. 0 means there is no limit. Default value: 30_000.

    • reconnectThrottlingRetries - Reconnect throttling retries. 0 means there is no limit. Default value: 3.

    • username - username for basic authentication to the cluster.

    • password - user password for basic authentication to the cluster.

    • sslEnabled - Determines if SSL is enabled. Possible values: true, false. Default value: false

      • trustStorePath - Path to trust store on client side.

      • trustStorePassword - Trust store password.

      • keyStorePath - Path to key store on client side.

      • keyStorePassword - Key store password.

      • clientAuth - SSL client authentication. Possible values: NONE, OPTIONAL, REQUIRE.

      • ciphers - comma-separated SSL ciphers list.

Parameter Precedence

If the same parameters are passed by using different means, the JDBC driver prioritizes them in the following way:

  1. API arguments passed in the Connection objects;

  2. Last instance of the parameter in the connection string;

  3. Properties object passed during connection.

Performing Transactions

With the JDBC driver, you can perform commit and rollback transactions. For more information about transactions, see Performing Transactions.

Here is how you can commit a transaction:

// Open the JDBC connection.
Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800");

// Commit a transaction
conn.commit();

You can also configure GridGain to automatically commit transactions by using the setAutoCommit() method.

Here is how you can rollback a transaction:

conn.rollback();