public class SpreadsheetGenerator { void dailyreport( Connection con) throws SQLException, IOException { Statement statement = con.createStatement(); ResultSet resultSet = null; try { resultSet = statement.executeQuery("select * from ssa_msg_daily"); } catch (Exception e) { } finally { ResultSet resultSet = statement.executeQuery("select * from ssa_msg_daily"); XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet spreadsheet = workbook.createSheet("employe db"); XSSFRow row = spreadsheet.createRow(1); XSSFCell cell; cell = row.createCell(1); cell.setCellValue("id"); cell = row.createCell(2); cell.setCellValue("Sender"); cell = row.createCell(3); cell.setCellValue("Service"); cell = row.createCell(4); cell.setCellValue("Message_identifier"); cell = row.createCell(5); cell.setCellValue("Date"); cell = row.createCell(6); cell.setCellValue("Incoming"); cell = row.createCell(7); cell.setCellValue("Outgoing"); int i = 2; while (resultSet.next()) { row = spreadsheet.createRow(i); cell = row.createCell(1); cell.setCellValue(resultSet.getInt("id")); cell = row.createCell(2); cell.setCellValue(resultSet.getString("Sender")); cell = row.createCell(3); cell.setCellValue(resultSet.getString("Service")); cell = row.createCell(4); cell.setCellValue(resultSet.getString("Message_identifier")); cell = row.createCell(5); cell.setCellValue(resultSet.getDate("Date")); cell = row.createCell(6); cell.setCellValue(resultSet.getString("Incoming")); cell = row.createCell(7); cell.setCellValue(resultSet.getString("Outgoing")); i++; } FileOutputStream out = new FileOutputStream(new File("exceldatabase.xlsx")); workbook.write(out); out.close(); System.out.println("exceldatabase.xlsx written successfully"); } } }
here ssa_msg_daily contains blank or null values in the table,so
while compiling i am getting error as
Exception in thread “main” java.lang.NoSuchFieldError: RETURN_NULL_AND_BLANK
occurs @ XSSFWorkbook workbook = new XSSFWorkbook(); how can i handle this situation and i am using the resultset to convert to spreedsheet using apache poi
Advertisement
Answer
You’ve got a classpath issue. You have a mix of versions of the Apache POI project on your classpath. This mix of versions is causing a newer version of one of the classes to try to talk to one of the older ones and they aren’t compatible.
The solution is to check your classpath (so, if you’re using maven, gradle, or some other dependency system, the chain of dependencies), and fix it up. Possibly it’s as simple as running a ‘clean’ command on your build system.
NB: Your code is very bad style – don’t put a ton of code in finally blocks. Furthermore, 99.9% of your paste is a red herring. This one-liner will cause your problem already:
XSSFWorkbook workbook = new XSSFWorkbook();
The rest is irrelevant.