Querying and Modifying Data
How to connect to a GridGain cluster with the ODBC driver and run SQL queries to select, insert, update, and delete data.
Overview
This page elaborates on how to connect to a cluster and execute a variety of SQL queries using the ODBC driver.
At the implementation layer, the ODBC driver uses SQL Fields queries to retrieve data from the cluster. This means that from ODBC side you can access only those fields that are defined in the cluster configuration.
Moreover, the ODBC driver supports DML (Data Modification Layer), which means that you can modify your data using an ODBC connection.
Configuring the Cluster
As the first step, you need to set up a configuration that will be used by the cluster nodes. The configuration should include caches configurations as well with properly defined QueryEntities properties. QueryEntities are essential for the cases when your application (or the ODBC driver in our scenario) is going to query and modify the data using SQL statements. Alternatively you can create tables using DDL.
SQLHENV env;
// Allocate an environment handle
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
// Use ODBC ver 3
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC3), 0);
SQLHDBC dbc;
// Allocate a connection handle
SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
// Prepare the connection string
SQLCHAR connectStr[] = "DSN=My Ignite DSN";
// Connecting to the Cluster.
SQLDriverConnect(dbc, NULL, connectStr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_COMPLETE);
SQLHSTMT stmt;
// Allocate a statement handle
SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
SQLCHAR query1[] = "CREATE TABLE Person ( "
"id LONG PRIMARY KEY, "
"firstName VARCHAR, "
"lastName VARCHAR, "
"salary FLOAT) "
"WITH \"template=partitioned\"";
SQLExecDirect(stmt, query1, SQL_NTS);
SQLCHAR query2[] = "CREATE TABLE Organization ( "
"id LONG PRIMARY KEY, "
"name VARCHAR) "
"WITH \"template=partitioned\"";
SQLExecDirect(stmt, query2, SQL_NTS);
SQLCHAR query3[] = "CREATE INDEX idx_organization_name ON Organization (name)";
SQLExecDirect(stmt, query3, SQL_NTS);As you can see, we defined two caches that will contain the data of Person and Organization types. For both types, we listed specific fields and indexes that will be read or updated using SQL.
Connecting to the Cluster
After the cluster is configured and started, we can connect to it from the ODBC driver side. To do this, you need to prepare a valid connection string and pass it as a parameter to the ODBC driver at the connection time. Refer to the Connection String page for more details.
Alternatively, you can also use a pre-configured DSN for connection purposes as shown in the example below.
Querying Data
After everything is up and running, we're ready to execute SQL SELECT queries using the ODBC API.
Inserting Data
To insert new data into the cluster, SQL INSERT statements can be used from the ODBC side.
Next, we are going to insert additional organizations without the usage of prepared statements.
Updating Data
Let's now update the salary for some of the persons stored in the cluster using SQL UPDATE statement.
Deleting Data
Finally, let's remove a few records with the help of SQL DELETE statement.
Batching With Arrays of Parameters
The ODBC driver supports batching with arrays of parameters for DML statements.
Let's try to insert the same records we did in the example above but now with a single SQLExecute call:
Streaming
The ODBC driver allows streaming data in bulk using the SET command. See the SET command documentation for more information.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

