You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Fillo读取Excel多参数报错:Recordset.getField不兼容String[]参数

Fixing the Fillo getField Argument Mismatch Error for Multi-Parameter Queries

Hey there, let's break down why you're seeing that error and how to fix it quickly.

The Root Cause

The error message says it all: getField(String) only accepts a single string argument, but you're passing multi_data—which is a String array (since String... in Java is syntactic sugar for a String array). You can't pass an array directly to a method that expects a single string, hence the mismatch.

The Solution

You need to loop through each field name in the multi_data array, call getField() on each one individually, and concatenate the results. Using a StringBuilder is the most efficient way to do this instead of chaining string concatenations.

Here's the revised code:

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()) { 
        // Use StringBuilder for efficient string concatenation
        StringBuilder fieldValues = new StringBuilder();
        // Add the first required field
        fieldValues.append(rs.getField(field));
        
        // Loop through all additional fields in multi_data
        for (String additionalField : multi_data) {
            // Optional: Add a separator like " | " for readability
            fieldValues.append(" | ").append(rs.getField(additionalField));
        }
        
        excel_data.add(fieldValues.toString());
    } 
    
    for (Object data: excel_data) { 
        System.out.println(data); 
    } 
    rs.close(); 
    connection.close(); 
}

Key Changes Explained

  1. StringBuilder Usage: Avoids the overhead of creating multiple string objects with each concatenation, which is better for performance especially if you're dealing with many rows or fields.
  2. Loop Through multi_data: Iterates over each field name in the variable arguments array, calling getField() on each one to fetch its value.
  3. Optional Separator: Added a | separator between values to make the output more readable—you can change this to any character/string you prefer, or remove it if you want raw concatenation.

Your existing call function_class.read_by_excel("select * from Sheet1 where employee_id = 60546", "department","salary"); will work perfectly with this updated code.

内容的提问来源于stack exchange,提问作者user3814582

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:28:28