0

在将结果集导出到 csv 时,我需要一个通用标题行,下面提到的是我的代码的一部分。请给我一个向 csv 添加通用标题的解决方案。现在这段代码给了我结果集中的行和列,我需要在我的 excel 表的左上角有一个标题部分。 Excel 工作表示例

getDataList = "{call getDataExport(?)}";
            callableStatement = sqlConnection.prepareCall(getDataList);
            callableStatement.setString(1, WhereClauses.toString());
            
            boolean results = callableStatement.execute();

            if (results) {
                resultSet = callableStatement.getResultSet();
                StringWriter stringWriter = new StringWriter();
                CSVWriter csvWriter = new CSVWriter(stringWriter);
                csvWriter.writeAll(resultSet, true); // including column names
                String resultss = stringWriter.toString();
                System.out.println("Output stream: " + resultss);
                resultss = resultss.replaceAll("\\<.*?\\>", "");
                resultss = resultss.replaceAll("&nbsp;", " ");
                data = resultss.getBytes("UTF-8");
                csvWriter.close();
             }
            resultSet.close();
            callableStatement.close();
            sqlConnection.commit();

4

0 回答 0