Pesquisar

記事
· 2025年11月30日 4m read

Connecting Java to InterSystems IRIS using JDBC

In the previous article, we talked about ODBC and connecting from C#. And now, let's look at JDBC and Java. The InterSystems JDBC driver is the recommended, high-performance way to integrate your Java applications.

Here is a step-by-step guide to getting your Java application connected to an IRIS instance using the JDBC driver.

Step 1: Obtain and Include the InterSystems IRIS JDBC Driver

Unlike ODBC drivers, which are often installed system-wide, JDBC drivers are typically distributed as JAR files that must be included in your Java project's classpath.

If InterSystems IRIS is installed on your local machine or another you have access to, you can find the file in install-dir/dev/java/lib/ or similar, where install-dir is the installation directory for the instance. Conversely, you can download the jar file from Driver packages page.

Or as suggested by @Dmitry Maslennikov in the comments, use the maven central repository for Maven:

<dependency>
    <groupId>com.intersystems</groupId>
    <artifactId>intersystems-jdbc</artifactId>
    <version>3.10.5</version>
</dependency>

or for Gradle:

implementation("com.intersystems:intersystems-jdbc:3.10.5")

Include the jar file in Project:

  • Maven/Gradle: If you use a build tool, the simplest method is to add the InterSystems JDBC driver as a dependency in your pom.xml or build.gradle file. This automatically downloads and manages the JAR.
  • Manual: For simple projects, you must place the JAR file in a project directory (e.g., /lib) and explicitly add it to your classpath when compiling and running.

Step 2: Define the JDBC Connection

The JDBC connection URL specifies exactly where and how the Java application connects to the database. It is formatted as jdbc:<subprotocol>://<host>:<port>/<namespace>.

The format for InterSystems IRIS is:

String url = "jdbc:IRIS://127.0.0.1:1972/USER";
String user = "_System";
String password = "SYS";

Note:

  • The Driver Prefix is jdbc:IRIS.
  • 127.0.0.1 is the server address (change this for remote connections).
  • 1972 is the IRIS SuperServer port (the standard is usually 1972 or 51773).
  • USER is the target Namespace in InterSystems IRIS where your code and data reside.
  • The default user is _System with the password SYS. Always change these defaults in a production environment.

Step 3: Implement the Connection in Java

We will use the standard java.sql package to establish the connection and execute a query.

Here is a minimal Java example that connects to IRIS, executes a simple query against a default table, and displays the result using try-with-resources for reliable connection management.

package com.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
	
public class IrisJdbcConnector {

    public static void main(String[] args) {
        
        // 1. Define the connection details
        String url = "jdbc:IRIS://127.0.0.1:1972/USER";
        String user = "_System";
        String password = "SYS";
        
        int maxId = 5; // Parameter for the query
        // The try-with-resources block ensures all resources are closed automatically
        try (
            // 2. Establish the connection
            Connection conn = DriverManager.getConnection(url, user, password);
            
            // 3. Define the SQL Query using a placeholder (?)
            PreparedStatement pstmt = conn.prepareStatement("SELECT ID, Name, DOB FROM Sample.Person WHERE ID < ?")
        ) {
            System.out.println("Connection to InterSystems IRIS successful!");

            // 4. Bind the parameter value
            pstmt.setInt(1, maxId);

            // 5. Execute the query
            try (ResultSet rs = pstmt.executeQuery()) {
                
                System.out.println("--- Query Results ---");
                
                // 6. Iterate through the results
                while (rs.next()) {
                    // Access data by column name
                    int id = rs.getInt("ID");
                    String name = rs.getString("Name");
                    // JDBC automatically handles the mapping of IRIS types to Java types (e.g., Date)
                    String dob = rs.getDate("DOB").toString(); 
                    
                    System.out.println(String.format("ID: %d, Name: %s, DOB: %s", id, name, dob));
                }
            }
            
        } catch (SQLException e) {
            // 7. Handle JDBC-specific exceptions (e.g., connection failure, invalid SQL)
            System.err.println("\n--- Database Error ---");
            System.err.println("SQL State: " + e.getSQLState());
            System.err.println("Error Message: " + e.getMessage());
            System.err.println("Ensure the IRIS server is running and the JDBC driver JAR is in the classpath.");
        } catch (Exception e) {
            System.err.println("\n--- General Error ---");
            System.err.println(e.getMessage());
        }
    }
}

❗ As with all database connections, always use prepared statements (similar to parameterized queries) in production code to prevent SQL injection vulnerabilities.

2 Comments
ディスカッション (2)2
続けるにはログインするか新規登録を行ってください
ダイジェスト
· 2025年11月28日

活动时间延长!InterSystems 2025开发者创意大赛期待您的精彩提交

亲爱的开发者,

🏆InterSystems 2025开发者创意大赛:让梦想落地🏆活动时间延长一周!

活动将由美国东部时间2025 年 11 月 17 日至 12 月 7 日延长至2025年12月14日! (项目提交时间延长至12月7日)

在本次竞赛中,我们希望参赛者能够实现 InterSystems 创意门户网站中任意创建于本公告发布之前(美国东部时间2025年11月7日之前)、状态为Community Opportunity(社区共建机遇)Future Consideration(待研功能提案)的优秀创意。

最新的重要截止日期:

🛠 应用程序开发和注册阶段:

  • 美国东部时间 2025 年 11 月 17 日(00:00):竞赛开始。
  • 美国东部时间 2025 年 12 月 7 日(23:59):提交截止日期。

✅ 投票阶段:

  • 美国东部时间 2025 年 12 月 8 日 (00:00):投票开始。
  • 美国东部时间 2025 年 12 月 14 日(23:59):投票结束。

关于赛事规则及详情,请点击查看👉这篇帖子

如果您已经非常了解规则了,或者已经准备好了您的应用,欢迎👉直达参赛页面,提交您的精彩应用!

お知らせ
· 2025年11月28日

[Video] Query Optimization in Hybrid Databases

Hey Community!

We're happy to share a new video from our InterSystems Developers YouTube:

⏯  Query Optimization in Hybrid Databases @ Ready 2025

This presentation covers query optimization in hybrid databases that use a mix of row-based, columnar, and bitmap indexes. InterSystems Iris supports flexible storage and indexing, but choosing the best combination for performance poses challenges. In version 2025.2, the query optimizer has been enhanced to fully integrate columnar indexing into its cost-based model. This allows the engine to automatically combine different index types, such as using a bitmap index for low-cardinality filters and a columnar index for analytical conditions within the same query.

The result is significant performance gains, with some queries running up to three times faster and minimal need for manual tuning. Future improvements will expand the optimizer to handle more vector operations and continue refining cost-based decision-making.

Presenters:
🗣 Ismail Ben Atitallah, Principal Systems Developer, InterSystems
🗣 Boya Song, Senior Systems Developer, InterSystems

Enjoy watching, and subscribe for more videos! 👍

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
お知らせ
· 2025年11月28日

NOVO: Programa de Acesso Antecipado para "Modelos Personalizados do IntegratedML" -- Implante seus modelos de aprendizado de máquina em Python diretamente em SQL

Temos o prazer de anunciar o Programa de Acesso Antecipado para Modelos Personalizados do IntegratedML, um novo e poderoso recurso que estará disponível no IRIS 2026.1!

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
質問
· 2025年11月28日

Punctually access specific nodes of an XML document

Hello!
I have the following XML document obtained through a string:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MainDocument xmlns="urn:hl7-org:v3">
<realmCode code="IT"/>
<title>kjbkjkjbkjb</title>
<effectiveTime value="20090905150716"/>
[.....other tags.....]
<versionNumber value="1"/>
<component>
<body>mhvjhjkvhj</body>
<component>
<section>content</section>
<ID>5</ID>
<title>Certificato</title>
<text/>
<entry>
<Id>5</Id>
[...other tags...]
</entry>
<entry>
<Id>6</Id>
[...other tags...]
</entry>
</component>
</component>
</ClinicalDocument>


I would like to have a way to obtain only the content of the <entry> tags (which can be multiple) without having to scan the whole xml document, since it would be inefficient because of its length. I would like to have an outcome similar to the one coming from EvaluateExpression() but, from my trials and examples found on the internet, it seems that this function can be used only when the tag contains just one value. Does anybody have any idea which might help?

Thank you in advance!

7 Comments
ディスカッション (7)3
続けるにはログインするか新規登録を行ってください