JDBC Client Driver
JDBC Client Driver interacts with the cluster by means of a client node.
JDBC Client Driver
The JDBC Client Driver connects to the cluster by using a lclient node connection. You must provide a complete Spring XML configuration as part of the JDBC connection string, and copy all the JAR files mentioned below to the classpath of your application or SQL tool:
-
All the JARs under
{IGNITE_HOME}\libs
directory. -
All the JARs under
{IGNITE_HOME}\ignite-indexing
and{IGNITE_HOME}\ignite-spring
directories.
The driver itself is more robust, and might not support the latest SQL features of Ignite. However, because it uses the client node connection underneath, it can execute and distribute queries, and aggregate their results directly from the application side.
The JDBC connection URL has the following pattern:
jdbc:ignite:cfg://[<params>@]<config_url>
Where:
-
<config_url>
is required and must represent a valid URL that points to the configuration file for the client node. This node will be started within the Ignite JDBC Client Driver when it (the JDBC driver) tries to establish a connection with the cluster. -
<params>
is optional and has the following format:
param1=value1:param2=value2:...:paramN=valueN
The name of the driver’s class is org.apache.ignite.IgniteJdbcDriver
. For example, here’s how to open a JDBC connection to the Ignite cluster:
// Registering the JDBC driver.
Class.forName("org.apache.ignite.IgniteJdbcDriver");
// Opening JDBC connection (cache name is not specified, which means that we use default cache).
Connection conn = DriverManager.getConnection("jdbc:ignite:cfg://config/ignite-jdbc.xml");
Note
|
Securing ConnectionFor information on how to secure the JDBC client driver connection, you can refer to the Security documentation. |
Supported Parameters
Parameter | Description | Default Value |
---|---|---|
|
Cache name. If it is not defined, then the default cache will be used. Note that the cache name is case sensitive. |
None. |
|
ID of node where query will be executed. Useful for querying through local caches. |
None. |
|
Query will be executed only on a local node. Use this parameter with the |
|
|
Flag that is used for optimization purposes. Whenever Ignite executes a distributed query, it sends sub-queries to individual cluster members. If you know in advance that the elements of your query selection are colocated together on the same node, Ignite can make significant performance and network optimizations. |
|
|
Allows use of distributed joins for non-colocated data. |
|
|
Turns on bulk data load mode via INSERT statements for this connection. Refer to the Streaming Mode section for more details. |
|
|
Tells Ignite to overwrite values for existing keys on duplication instead of skipping them. Refer to the Streaming Mode section for more details. |
|
|
Timeout, in milliseconds, that data streamer should use to flush data. By default, the data is flushed on connection close. Refer to the Streaming Mode section for more details. |
|
|
Data streamer’s per node buffer size. Refer to the Streaming Mode section for more details. |
|
|
Data streamer’s per node parallel operations number. Refer to the Streaming Mode section for more details. |
|
|
Presently ACID Transactions are supported, but only at the key-value API level. At the SQL level, Ignite supports atomic, but not transactional consistency. This means that the JDBC driver might throw a However, in cases when you need transactional syntax to work (even without transactional semantics), e.g. some BI tools might force the transactional behavior, set this parameter to |
|
|
JDBC driver will be able to process multiple SQL statements at a time, returning multiple |
|
|
Enables server side update feature. When Ignite executes a DML operation, it first fetches all of the affected intermediate rows for analysis to the query initiator (also known as reducer), and then prepares batches of updated values to be sent to remote nodes. This approach might impact performance and saturate the network if a DML operation has to move many entries over it. Use this flag as a hint for Ignite to perform all intermediate rows analysis and updates "in-place" on the corresponding remote data nodes. Defaults to |
|
Note
|
Cross-Cache QueriesThe cache to which the driver is connected is treated as the default schema. To query across multiple caches, you can use Cross-Cache queries. |
Streaming Mode
It’s feasible to add data into a cluster in streaming mode (bulk mode) using the JDBC driver. In this mode, the driver instantiates IgniteDataStreamer
internally and feeds data to it. To activate this mode, add the streaming
parameter set to true
to a JDBC connection string:
// Register JDBC driver.
Class.forName("org.apache.ignite.IgniteJdbcDriver");
// Opening connection in the streaming mode.
Connection conn = DriverManager.getConnection("jdbc:ignite:cfg://streaming=true@file:///etc/config/ignite-jdbc.xml");
Presently, streaming mode is supported only for INSERT operations. This is useful in cases when you want to achieve fast data preloading into a cache. The JDBC driver defines multiple connection parameters that affect the behavior of the streaming mode. These parameters are listed in the parameters table above.
Warning
|
Cache NameMake sure you specify a target cache for streaming as an argument to the |
The parameters cover almost all of the settings of a general IgniteDataStreamer
and allow you to tune the streamer according to your needs. Please refer to the Data Streaming section for more information on how to configure the streamer.
Note
|
Time Based FlushingBy default, the data is flushed when either a connection is closed or |
// Register JDBC driver.
Class.forName("org.apache.ignite.IgniteJdbcDriver");
// Opening a connection in the streaming mode and time based flushing set.
Connection conn = DriverManager.getConnection("jdbc:ignite:cfg://streaming=true:streamingFlushFrequency=1000@file:///etc/config/ignite-jdbc.xml");
PreparedStatement stmt = conn.prepareStatement(
"INSERT INTO Person(_key, name, age) VALUES(CAST(? as BIGINT), ?, ?)");
// Adding the data.
for (int i = 1; i < 100000; i++) {
// Inserting a Person object with a Long key.
stmt.setInt(1, i);
stmt.setString(2, "John Smith");
stmt.setInt(3, 25);
stmt.execute();
}
conn.close();
// Beyond this point, all data is guaranteed to be flushed into the cache.
Example
To start processing the data located in the cluster, you need to create a JDBC Connection
object using one of the methods below:
// Register JDBC driver.
Class.forName("org.apache.ignite.IgniteJdbcDriver");
// Open JDBC connection (cache name is not specified, which means that we use default cache).
Connection conn = DriverManager.getConnection("jdbc:ignite:cfg://file:///etc/config/ignite-jdbc.xml");
Right after that you can execute your SQL SELECT
queries:
// Query names of all people.
ResultSet rs = conn.createStatement().executeQuery("select name from Person");
while (rs.next()) {
String name = rs.getString(1);
}
// Query people with specific age using prepared statement.
PreparedStatement stmt = conn.prepareStatement("select name, age from Person where age = ?");
stmt.setInt(1, 30);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
String name = rs.getString("name");
int age = rs.getInt("age");
}
You can use DML statements to modify the data.
INSERT
// Insert a Person with a Long key.
PreparedStatement stmt = conn.prepareStatement("INSERT INTO Person(_key, name, age) VALUES(CAST(? as BIGINT), ?, ?)");
stmt.setInt(1, 1);
stmt.setString(2, "John Smith");
stmt.setInt(3, 25);
stmt.execute();
MERGE
// Merge a Person with a Long key.
PreparedStatement stmt = conn.prepareStatement("MERGE INTO Person(_key, name, age) VALUES(CAST(? as BIGINT), ?, ?)");
stmt.setInt(1, 1);
stmt.setString(2, "John Smith");
stmt.setInt(3, 25);
stmt.executeUpdate();
UPDATE
// Update a Person.
conn.createStatement().
executeUpdate("UPDATE Person SET age = age + 1 WHERE age = 25");
DELETE
conn.createStatement().execute("DELETE FROM Person WHERE age = 25");
Apache, Apache Ignite, the Apache feather and the Apache Ignite logo are either registered trademarks or trademarks of The Apache Software Foundation.