如何在 SpringBoot 中集成 SPL-Esproc(集算器)

本文介绍了如何在SpringBoot中集成SPL-Esproc,包括手动导入Jar包、配置raqsoftConfig.xml文件以及解决语句执行异常的方法。通过示例代码展示了正确读取数据文件并执行SPL语句的过程,最终成功输出数据。
摘要由CSDN通过智能技术生成

如何在 SpringBoot 中集成 SPL-Esproc(集算器)
参考:http://d.raqsoft.com.cn:6999/esproc/tutorial/pzraqsoftconfig.html:官方提供的配置方式

问题描述:
$()select * from users.txt 这条语句会抛语法错误的异常
但是按下面这种通过绝对路径读取的方式就可行

=file(\"D://mainFile//users.txt\").import@t() 

在这里插入图片描述

解决办法:

1.添加依赖 或者 手动导入 Jar 包,参考:手动导jar包
我采用的是手动导入jar包的方式,这三个基础包

Jar包来源:安装好官网下载的软件后,在如图所示目录中查找

2.将 raqsoftConfig.xml 文件放在 resources 下面程序才能读取到(在Idea中的位置如图所示)

3.修改 raqsoftConfig.xml 配置中到识别路径(图中两个标识处都配置为自己电脑中,数据文件存放的路径)

4.编写语句测试

public void runSPL2() throws ClassNotFoundException, SQLException {
    Connection con = null;
    PreparedStatement st;
    ResultSet set;
    //建立连接
    Class.forName("com.esproc.jdbc.InternalDriver");
    //onlyServer用于控制当前jdbc是否对服务器进行远程计算,为true表示远程计算;false时表示本地计算
    //注意:属性值为false,当SPL语句使用call dfx或dfx时,会先使用本地计算,如未计算成功则会进行远程计算
    // con= DriverManager.getConnection("jdbc:esproc:local://?onlyServer=true");
    con = DriverManager.getConnection("jdbc:esproc:local://?onlyServer=false");
    //直接执行SPL语句,返回结果集
    st = (PreparedStatement) con.createStatement();

    ResultSet rs = st.executeQuery("$()select * from Absenteeism.txt");
    // ResultSet rs = st.executeQuery("=file(\"D://mainFile//users.txt\").import@t()");
    // ResultSet rs = st.executeQuery("=file(\"D://mainFile//User20220210.xlsx\").xlsimport@tx()");

    //简单处理结果集,将结果集中的字段名与数据输出
    ResultSetMetaData rsmd = rs.getMetaData();
    int colCount = rsmd.getColumnCount();
    for (int c = 1; c <= colCount; c++) {
        String title = rsmd.getColumnName(c);
        if (c > 1) {
            System.out.print("\t");
        } else {
            System.out.print("\n");
        }
        System.out.print(title);
    }
    while (rs.next()) {
        for (int c = 1; c <= colCount; c++) {
            if (c > 1) {
                System.out.print("\t");
            } else {
                System.out.print("\n");
            }
            Object o = rs.getObject(c);
            try {
                System.out.print(o == null ? " " : o.toString());
            } catch (Exception e) {
                // System.out.println("异常:===》"+e);
            }
        }
    }
    //关闭连接
    if (con != null) {
        con.close();
    }
}

输出结果

[2022-02-11 14:48:17] 
INFO: The block size is empty.

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
[2022-02-11 14:48:17] 
INFO: Config file: raqsoftConfig.xml has been loaded.

Employee	Absenteeism
1	0.13
2	0.13
5	0.06
6	0.13
7	0.13
8	0.03
9	0.33
12	0.2
14	0.13
15	0.13
16	0.33
17	0.3
20	0.26
23	0.1
Process finished with exit code 0

最后感谢 SPL 社区各位大佬的帮助,站在巨人的肩膀上我们才能看得更远

原文转载:yanqi的笔记

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值