This is the second part of an article pair where I walk you through:
- Part I - Intro and Quick Tour (the previous article)
- What is it?
- Spinning up an InterSystems IRIS Cloud Document deployment
- Taking a quick tour of the service via the service UI
- Part II - Sample (Dockerized) Java App (this article)
- Grabbing the connection details and TLS certificate
- Reviewing a simple Java sample that creates a collection, inserts documents, and queries them
- Setting up and running the Java (Dockerized) end‑to‑end sample
As mentioned the goal is to give you a smooth “first run” experience.

Previously we created an IRIS Cloud Document deployment (and took a quick tour), now let's see how we can interact with it from a Java app.
Assuming you want to take this for a drive, and go hands-on, you'll need Docker, and Git, and start by hoping over to the Open Exchange App, and cloning the GitHub repo.
4. Note the connection details
Once the deployment is running, open it and look at the Overview page. There’s a table called Making External Connections that lists:
Keep those values handy; we’ll plug them into the Java demo.
.png)
- Hostname (e.g.
k8s-your-hostname.elb.us-east-1.amazonaws.com) - Port (should be
443) - Namespace (should be
USER) - SQL username (should be
SQLAdmin) - Password (you set this when creating or configuring access)
(These Docs also might also help)
- Enable external connections
- Make sure external access is enabled, either for all IP addresses, or your client IP (or IP range) is allowed in the deployment firewall settings.
- This is done in the Cloud Services Portal when creating the service, or in the section mentioned above.
- Download the TLS certificate
- Cloud Document requires TLS. From the deployment overview there’s a link to download a self‑signed X.509 certificate for your deployment. You’ll use this certificate on your client side to establish a trusted TLS connection. Save it as something like:
certs/certificateSQLaaS.pem
- Cloud Document requires TLS. From the deployment overview there’s a link to download a self‑signed X.509 certificate for your deployment. You’ll use this certificate on your client side to establish a trusted TLS connection. Save it as something like:
That’s all we need from the portal: host, port, namespace, credentials, and the certificate file.
5. Review the Sample Accessing Cloud Document from Java
In general the pattern looks like:
- Make a secure connection (Connecting - Docs) - Configure
DataSource(server, port, namespace, user, password, TLS). - Ingest some data (Using Document and Collections - Docs) - Get a
Collectionby name (created automatically the first time). And buildJSONObject/JSONArrayinstances, insert them asDocuments. - Query / fetch data back (Querying - Docs) - Query using a
ShorthandQuery(string that behaves like aWHEREclause on the collection).
If you’ve used other document databases, this should feel pretty familiar.
The Java driver for Cloud Document lives in the package com.intersystems.document. It gives you three main pieces:
- DataSource – a connection pool to the Cloud Document server.
- Document – base class for JSON documents; usually you’ll use its subclasses:
JSONObject– JSON object withput()methods for key/value pairs.JSONArray– JSON array withadd()methods.
- Collection – represents a named collection; you can
insert,get,getAll,drop, and run queries.
The code and data used in this sample is based directly on the examples provided within our Documentation.
5.1 Making the connection
First, the bits we need for a basic connection:
- Hostname, port, namespace, user, password – from the deployment’s “external connections” information.
- The deployment’s X.509 certificate, imported into a Java keystore.
- A small
SSLConfig.propertiesfile so the driver knows which keystore to use.
Building a TLS-enabled DataSource
Here’s a compact example that focuses on the connection itself:
If SSLConfig.properties and keystore.jks are set up correctly, calling createDataSource() should establish a connection over TLS to your Cloud Document deployment.
The Cloud Document Java driver looks for this SSLConfig.properties file and uses it when you set connectionSecurityLevel to require TLS.
This is what this file would look like:
In the Docker sample I provided there is a script that takes care of this for you.
If you're running your own samples, you can use a line like this one:
keytool -importcert -file /path/to/certs/cloud-document.pem -keystore keystore.jks
- Answer
yeswhen asked if you want to trust the certificate. - Set a password and remember it.
In the Docker sample, our script does this:
5.2 Ingesting data from Java
Once we have a DataSource, we work with collections and documents.
Collectionis the named container, likecolorsordemoPeople.- A document is a
JSONObjectorJSONArrayextendingDocument.
Here’s a small “ingest” example that mirrors the colors JSON file we imported in the UI earlier.
A few notes:
Collection.getCollection(pool, name)will create the collection on first use if it doesn’t exist.insert()returns the document ID assigned by Cloud Document.insert(List<Document>)does a bulk write and returns all the IDs in aBulkResponse.
This is the same basic pattern you’d use in an application ingesting JSON from a file, a queue, or an API.
5.3 Querying and fetching data
On the Java side you have two main options:
- Use the collection-centric APIs (
getAll,createShorthandQuery, etc.). - Use regular SQL (for example with JDBC directly) and
JSON_TABLEwhen you want rich SQL projections.
For a first experience, the collection APIs are usually enough.
List all documents in a collection and searching for some
What’s happening here:
getAll()gives you every document in the collection asDocumentobjects.createShorthandQuery("name > 'H'")creates a query that’s conceptually similar toWHERE name > 'H'in SQL.Cursorlets you iterate the results and also ask for a count.
If you later want to bring this into the SQL world, the same collections you touched here can be queried with JSON_TABLE in the SQL UI or via JDBC. That’s one of the nice aspects of Cloud Document: you don’t have to choose between “document API” and “SQL”; you get both.
6. Setting up and Running the Sample
As mentioned I'm providing a Dockerized sample, to ensure a smooth as possible experience without requiring you to manually download and install various parts, but if you want you can use the same sample and run this on your own.
The Open Exchange and related GitHub repository include detailed instructions for running, but at high-level it comes down to simply:
6.1 Update .env file and place TLS certificate
This is what your environment variables file might look like after your edit it:
6.2 Run docker compose
Just run docker compose up --build and the sample will run.
behind the scenes we will:
- Stage 1: Use a Maven + JDK image to build a shaded JAR.
- Stage 2: Use a slim JDK image, copy the JAR and
SSLConfig.properties, create a keystore from your cert at container startup, then run the JAR.
Here's a short video demonstrating this:
Wrapping up
If you’re new to InterSystems but not new to programming, the basic path to a good first experience with IRIS Cloud Document is:
- Bring the service up: create a deployment, note host/port/namespace/credentials, download the certificate.
- Kick the tires in the web portal: upload a JSON file, import into a collection, browse with the Collection Browser, and run a simple SQL query with
JSON_TABLE. - Wire it into Java:
- create a TLS-enabled
DataSource(withSSLConfig.properties+ keystore), - use
CollectionandDocumentto ingest data, - and query with
getAlland shorthand queries.
- create a TLS-enabled
From there you can iterate toward more interesting things: updates, deletes, richer queries, combining Cloud Document data with relational data, or using other drivers like .NET.
But if you’ve followed along to this point and seen your own JSON documents come back from the Java code, you’ve already taken the most important step: you’re up and running in the InterSystems ecosystem.
Enjoy!
.png)
.png)
.png)
.png)
(Here I clicked Preview, which shows the contents, and summarizes that upon import 3 documents will be added).png)
.png)
.png)
.png)
.jpg)