如何在 SpringBoot 中集成 SPL-Esproc(集算器)
如何在 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包的方式,这三个基础包
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(" ");
} else {
System.out.print("
");
}
System.out.print(title);
}
while (rs.next()) {
for (int c = 1; c <= colCount; c++) {
if (c > 1) {
System.out.print(" ");
} else {
System.out.print("
");
}
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 社区各位大佬的帮助,站在巨人的肩膀上我们才能看得更远
