gpt4 book ai didi

java - Recordset 不适用于参数 (String[]) -- 接受多个参数时出错

转载 作者:行者123 更新时间:2023-12-02 11:42:22 26 4
gpt4 key购买 nike

我尝试使用 Excel 作为数据库,并使用了 fillo 依赖项。我尝试过使用单个参数,效果很好。但是当我尝试使用多个参数时,它会弹出以下错误:

" The method getField(String) in the type Recordset is not applicable for the arguments (String[])", error is on "multi_data".

这是代码:

public static void read_by_excel(String query, String field, String ... multi_data) throws FilloException
{

ArrayList<Object> excel_data = new ArrayList<Object>();
Fillo fillo = new Fillo();
Connection connection = fillo.getConnection("C:\\Users\\Vishrut\\Desktop\\read_openxl.xlsx");
String strQuery = query;
Recordset rs = connection.executeQuery(strQuery);

while (rs.next())
{
excel_data.add(rs.getField(field)+rs.getField(multi_data));

}

for (Object data: excel_data)
{
System.out.println(data);
}
rs.close();
connection.close();
}

这里是如何称呼的。 “department”后面可以带多个参数。

    function_class.read_by_excel("select * from Sheet1 where employee_id = 60546", "department","salary");

最佳答案

我认为错误消息很清楚,getField(String)方法不支持传递数组。

从您的代码中,multi_data 参数是一个数组

String ... multi_data

然后将其传递给 getField 方法

rs.getField(multi_data)

这是我的做法:更改方法签名

public static void read_by_excel(Integer emplyoee_id, String ...fields){
//...
}

然后替换

rs.getField(field) + rs.getField(multi_data)

Stream.of(fields).map(f -> rs.getField(f)).collect(Collectors.joining());

请注意,我假设 getField返回 String (fillo 没有公共(public) API 文档,因此无法验证)。请注意,确保您确实想做 rs.getField(field) + rs.getField(multi_data)值之间没有分隔符。考虑使用joining(",")或其他任何东西。

关于java - Recordset 不适用于参数 (String[]) -- 接受多个参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48461001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com