0

I am trying to write the output of a complex query into Excel. For this I am using JDBC and created a function of return type 'ResultSet' through which I'll be getting the output of the Query.

To write the ResultSet Rows into excel, I should do like below:

        HSSFRow row = firstSheet.createRow(index);
    row.createCell(0).setCellValue(rs.getInt(1));
    row.createCell(1).setCellValue(rs.getInt(2));
    row.createCell(2).setCellValue(rs.getString(2));
    row.createCell(3).setCellValue(rs.getString(3));

Now The issue is, the resultset of the complex query includes variable number of rows and columns depending upon the date we run the query which need to be exported to excel. Is there any feasible approach through programming I can handle this situation and export the query result into an excel.

Thanks in advance.

0

1 Answer 1

2

You should use ResultSet.getMetaData() method and, for example, iterate for ResultSetMetaData.getColumnCount() times.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.