Nueva publicación

Encontrar

Artículo
· 8 hr atrás Lectura de 4 min

使用 JDBC 将 Java 连接到 InterSystems IRIS

在上一篇文章中,我们谈到了 ODBC 和 C# 连接,现在让我们看看 JDBC 和 Java。InterSystems JDBC 驱动程序是集成 Java 应用程序的高性能推荐方式。

以下是使用 JDBC 驱动程序将 Java 应用程序连接到 IRIS 实例的分步指南。

第 1 步:获取并包含 InterSystems IRIS JDBC 驱动程序

JDBC 驱动程序与 ODBC 驱动程序不同,后者通常安装在整个系统中,而 JDBC 驱动程序通常以JAR 文件的形式发布,必须包含在 Java 项目的类路径中。

如果 InterSystems IRIS 安装在本地计算机或您可以访问的其他计算机上,您可以在 install-dir/dev/java/lib/ 或类似位置找到该文件,其中 install-dir 是实例的安装目录。反之,您也可以从驱动程序软件包页面下载 jar 文件。

或者按照 @Dmitry Maslennikov 在评论中的建议 ,使用 Maven 的maven 中央仓库

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

或 Gradle:

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

在项目中包含 jar 文件:

  • Maven/Gradle:如果使用构建工具,最简单的方法是将 InterSystems JDBC 驱动程序作为依赖项添加到 pom.xmlbuild.gradle 文件中。这会自动下载并管理 JAR。
  • 手册:对于简单的项目,必须将 JAR 文件放在项目目录(如 /lib)中,并在编译和运行时将其明确添加到 classpath 中。

第 2 步:定义 JDBC 连接

JDBC 连接 URL 明确规定了 Java 应用程序连接数据库的位置和方式。其格式为 jdbc:<subprotocol>://<host>:<port>/<namespace>

InterSystems IRIS 的格式为

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

注意:

  • 驱动程序前缀jdbc:IRIS
  • 127.0.0.1 是服务器地址(远程连接时更改)。
  • 1972 是 IRIS超级服务器端口(标准端口通常为 1972 或 51773)。
  • USER 是代码和数据所在的 InterSystems IRIS 目标命名空间
  • 默认的 user_System,密码是 SYS请务必在生产环境中更改这些默认值。

第 3 步:用 Java 实现连接

我们将使用标准java.sql包建立连接并执行查询。

下面是一个最小的 Java 示例,它连接到 IRIS,针对默认表执行简单查询,并使用try-with-resources显示结果,以实现可靠的连接管理。

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());
        }
    }
}

❗与所有数据库连接一样,在生产代码中始终使用预处理语句(类似于参数化查询),以防止 SQL 注入漏洞。

Comentarios (0)1
Inicie sesión o regístrese para continuar
InterSystems Official
· 10 hr atrás

InterSystems任命Don Woodlock为总裁

2026 年 1 月 6 日,马萨诸塞州 波士顿——创新数据技术公司InterSystems今日宣布,即日起,Don Woodlock被任命为总裁,全面负责领导公司的日常运营工作。在领导公司长达47年之后,创始人、所有者兼首席执行官Phillip “Terry” Ragon将卸下日常管理职责,转而专注于指导公司的业务和技术战略。Ragon将继续担任首席执行官一职,并与领导团队紧密合作,确保公司平稳过渡,继续秉持对卓越品质和客户成功的承诺。
“在2023年全球峰会上发言时,我谈到了强大而稳定的文化如何具有韧性,以及文化为何是预测未来成功最有力的指标。”Ragon表示,"我相信,我们在InterSystems所建立的文化真正实现了自我延续,现在是时候让下一代来接棒,成为我们所有人共同努力成果的管理者了。"
Woodlock已在InterSystems担任医疗业务副总裁长达八年。他拥有深厚的行业专业知识和敏锐的技术洞察力,并与公司“以客户为先”的文化理念高度契合。

"自2017年加入InterSystems以来,Terry一直是我的榜样和导师。"Woodlock表示,"早在几十年前,我就开始接触和使用InterSystems的产品,起初是担任技术职务,后来则领导一个为医疗健康领域提供解决方案的业务部门。这些来自一线的真实客户经验,再结合InterSystems在技术、财务和组织方面的优势,激发了我帮助公司迈向下一个成功时代的激情。”

点击这里,认识我们的领导团队

Comentarios (0)1
Inicie sesión o regístrese para continuar
Resumen
· 10 hr atrás

InterSystems 开发者社区中文版:每周摘要(1月19日-25日)

一月 19 - 25, 2026Week at a GlanceInterSystems Developer Community
Artículo
· 13 hr atrás Lectura de 2 min

Reviews on Open Exchange - #63

If one of your packages on OEX receives a review, you get notified by OEX only of YOUR own package.   
The rating reflects the experience of the reviewer with the status found at the time of review.   
It is kind of a snapshot and might have changed meanwhile.   
Reviews by other members of the community are marked by * in the last column.

I also placed a bunch of Pull Requests on GitHub when I found a problem I could fix.    
Some were accepted and merged, and some were just ignored.     
So if you made a major change and expect a changed review, just let me know.
 

# Package Review Stars IPM Docker *
1 IRIS OpenTelemetry Demo impressive 7 containers concert 5.5   y  
2 DBdashboard impressive catch 5.0   y *
3 DBfree super multi instance monitoring 5.0   y *
4 IRIS-EchoServer-WebSockets echo inside IRIS 5.0   y *
5 iris-health-fhir-agentic-demo not just big but great 5.0   y *
6 ML Made Easy : IntegratedML an excellent training for beginners 5.0   y  
7 restoreUI a pleasure to work with 5.0 y y  
8 WebSocketsSample hidden treasure detected 5.0      
9 CSV-to-MS-OFX rare subject 4.8   y *
10 GeoDatas works partially 3.5   y  
11 CommunityEns requires some adjustments 3.3   y  
12 ALPHA LOGISTICS partner posting *      
13 ERP Plenum partner posting *      

 

NOTE:
If some review is not readable for you, it might still wait for approval by OEX admins.

Comentarios (0)1
Inicie sesión o regístrese para continuar
Comentarios
· 16 hr atrás

Global Masters - Random Coffee Chat - Asia & Pacific

Hi Community! 👋

You’ve asked for easier ways to connect with other Global Masters and we heard you!
Random Coffee Chat is an easy way for Global Masters to connect and have an informal 1:1 conversation. ☕

🗓 When: January 26 – February 9

This thread is for participants based in Asia, Australia and New Zealand who’d like to connect and schedule a short coffee chat directly with each other.

 
☕ How it works

  • Leave a comment in this thread to join
  • Reply to someone’s comment if you’d like to connect
  • Continue the conversation in Direct Messages and schedule a 30-minute quick call

You choose who to connect with and when.

Participants connect directly with each other via Direct Messages on the Developer Community and choose a time that works best for both sides.

☕ After your coffee chat, share a quick screenshot from your call in the Random Coffee Chat ASK on Global Masters, and earn 100 Global Masters points as a thank-you for participating.

💬 Example comment (copy & paste)

Hi! I’m in for a random coffee chat ☕
Location: Australia
Availability: Wed–Fri, 10:00–13:00
Happy to chat about: getting to know each other, AI & automation, READY 2026 plans

🧠 Suggested topics & ice breakers

  • Just getting to know each other and what you enjoy outside of work 
  • AI, automation, and agent-based solutions
  • Developer tools, productivity, and workflows
  • Community contributions and favorite DC topics
  • InterSystems READY plans and past event experiences

⏱ Format

  • 30-minute informal video or audio call
  • Any tool that works for both of you

Looking forward to seeing new connections happen here 🚀

Comentarios (0)1
Inicie sesión o regístrese para continuar