JDBC driver thin implementation for In-Memory Data Grid.
Driver allows to get distributed data from Ignite cache using standard
SQL queries and standard JDBC API. It will automatically get only fields that
you actually need from objects stored in cache.
Data in Ignite cache is usually distributed across several nodes,
so some queries may not work as expected since the query will be sent to each
individual node and results will then be collected and returned as JDBC result set.
Keep in mind following limitations (not applied if data is queried from one node only,
or data is fully co-located or fully replicated on multiple nodes):
-
Joins will work correctly only if joined objects are stored in
collocated mode. Refer to
AffinityKey
javadoc for more details.
-
Note that if you are connected to local or replicated cache, all data will
be queried only on one node, not depending on what caches participate in
the query (some data from partitioned cache can be lost). And visa versa,
if you are connected to partitioned cache, data from replicated caches
will be duplicated.
Driver allows to query data from several caches. Cache that driver is connected to is
treated as default schema in this case. Other caches can be referenced by their names.\
JDBC driver is located in main Ignite JAR in
IGNITE_HOME/libs
folder.
JDBC connection URL has the following pattern:
jdbc:ignite:thin://<hostname>:<port>/
Note the following:
- Hostname is required.
- If port is not defined,
10800
is used (default for Ignite thin client).
Other properties can be defined in
Properties
object passed to
DriverManager.getConnection(String, Properties)
method:
Name |
Description |
Default |
Optional |
ignite.jdbc.distributedJoins |
Flag to enable distributed joins. |
false (distributed joins are disabled) |
Yes |
ignite.jdbc.enforceJoinOrder |
Flag to enforce join order of tables in the query. |
false (enforcing join order is disabled) |
Yes |
// Open JDBC connection.
Connection conn = DriverManager.getConnection("jdbc:ignite:thin//localhost:10800");
// Query persons' names
ResultSet rs = conn.createStatement().executeQuery("select name from Person");
while (rs.next()) {
String name = rs.getString(1);
...
}
// Query persons with specific age
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");
...
}