首页 > 解决方案 > 用于访问 Excel 数据的 SQL 查询 - Java

问题描述

我正在尝试使用 Fillo-1.18 从 excel 中读取数据。下面是我的代码:

public static void main(String[] args) {
        Fillo fillo=new Fillo();
        Connection connection;
        try {
            connection = fillo.getConnection("C:\\Users\\Dish\\Desktop\\1.xlsx");

            String strQuery="Select sum(Amount) as amnt, Run_ID from Sheet1 group by Run_ID";
            Recordset recordset=connection.executeQuery(strQuery);

            while(recordset.next()){
                System.out.println(recordset.getField("amnt"));
            }

            recordset.close();
            connection.close();
        } catch (FilloException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

它适用于普通的选择子句。但是当我尝试使用像 SUM() 这样的聚合函数时,我无法访问该字段。在里面while我收到以下错误:

com.codoid.products.exception.FilloException: amnt field is not found
    at com.codoid.products.fillo.Recordset.getField(Recordset.java:163)
    at ReadExcelSheetData.main(ReadExcelSheetData.java:18)

我该如何解决这个问题?

标签: javaexcel

解决方案


推荐阅读