Use the Java API
Build a Java application that connects to a GridGain 9 cluster and works with data through the RecordView and KeyValueView table APIs.
This guide walks you through creating a Java application that connects to an GridGain 9 cluster, demonstrating key patterns for working with data using GridGain's Java API.
Prerequisites
JDK 17 or later;
Maven;
Up-to-date versions of Docker and Docker Compose.
Setting Up GridGain 9 Cluster
Create a Docker Compose file to run a three-node GridGain cluster:
# docker-compose.yml
name: gridgain9
x-gridgain-def: &gridgain-def
image: gridgain/gridgain9:latest
environment:
JVM_MAX_MEM: "4g"
JVM_MIN_MEM: "4g"
BOOTSTRAP_NODE_CONFIG: /opt/gridgain/etc/gridgain-config.conf
configs:
- source: node_config
target: /opt/gridgain/etc/gridgain-config.conf
mode: 0644
services:
node1:
<<: *gridgain-def
command: --node-name node1
ports:
- "10300:10300" # REST API port
- "10800:10800" # Client port
node2:
<<: *gridgain-def
command: --node-name node2
ports:
- "10301:10300"
- "10801:10800"
node3:
<<: *gridgain-def
command: --node-name node3
ports:
- "10302:10300"
- "10802:10800"
configs:
node_config:
content: |
ignite {
network {
port: 3344
nodeFinder.netClusterNodes = ["node1:3344", "node2:3344", "node3:3344"]
}
}Starting and Initializing the Cluster
Start the cluster:
Run the GridGain CLI and initialize the cluster:
Inside the CLI, confirm the connection to the default node.
Initialize the cluster:
Enter the SQL mode:
Create a sample table and insert data:
Exit the SQL mode and CLI tool:
Setting Up Your Java Project
Create a Maven Project
First, create a simple Maven project. Below is the example of the project we will be using:
Configure Maven Dependencies
Include the GridGain client dependency in your pom.xml file:
Building Your Java Application
Now, let's create a Java application that connects to our GridGain cluster and performs various data operations.
Main Application Class
Create a Main.java file with the following code:
Running the Application
To run your application:
Make sure your GridGain cluster is up and running;
Compile and run your Java application:
Expected Output
You should see output similar to this:
Understanding Table Views in GridGain 9
GridGain 9 provides multiple view patterns for interacting with tables on top of providing a robust SQL API. Examples below showcase how you can work with GridGain tables from your project without SQL. For examples of working with SQL, see the Getting Started with SQL tutorial.
RecordView Pattern
RecordView treats tables as a collection of records, perfect for operations that work with entire rows:
KeyValueView Pattern
KeyValueView treats tables as a key-value store, ideal for simple lookups:
Cleaning Up
To stop your cluster when you are done:
Troubleshooting
If you encounter connection issues:
Verify your Docker containers are running with
docker compose pscommand;Check if the exposed ports match those in your client configuration;
Ensure that the
localhostinterface can access the Docker container network.
Next Steps
Now that you've explored the basics of connecting to GridGain and interacting with data:
Try implementing transactions;
Experiment with more complex schemas and data types;
Explore data partitioning strategies;
Investigate GridGain's distributed computing capabilities.
See Also
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

