Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8138161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:24:23+00:00 2026-06-06T11:24:23+00:00

I have this DAO.. public class AreaDAO { private Database database; public AreaDAO(Database database)

  • 0

I have this DAO..

public class AreaDAO {

    private Database database;

    public AreaDAO(Database database) {
        this.database = database;
    }

    public List<Area> list() throws SQLException {
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        List<Area> areas = new ArrayList<Area>();

        try {
            connection = database.getConnection();
            statement = connection.prepareStatement("select distinct img_hub, country from ifs_db limit 50");
            resultSet = statement.executeQuery();
            while (resultSet.next()) {
                Area area = new Area();
                area.setImg_hub(resultSet.getString("img_hub"));
                area.setCountry(resultSet.getString("country"));
                areas.add(area);
            }
        } finally {
            if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {}
            if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {}
            if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {}
        }

        return areas;
    }
}

this produce a list of data…

How can I let the user download all the data in excel by just clicking on the link..

I’ researched the we and found this…(by BalusC)

    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=name.xls");
    WritableWorkbook workBook  = Workbook.createWorkbook(response.getOutputStream());

I place it to my servlet, how ever I’m just getting a blank worksheet… how can I use this so I can let the user download a

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:24:25+00:00Added an answer on June 6, 2026 at 11:24 am

    I understand that you’re referring to my answer on this question? Note the // ... line, that’s where you should populate the workbook with the data from the DB. The OP of that question already knew that, so it was omitted for brevity.

    You can find on the POI HSSF own site a quick guide how to use the API.

    Here’s a kickoff example how to create a sheet with a cell.

    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=name.xls");
    WritableWorkbook workbook = Workbook.createWorkbook(response.getOutputStream());
    WritableSheet sheet = workbook.createSheet("Sheet1", 0);
    sheet.addCell(new Label(0, 0, "Hello World"));
    // ...
    workbook.write();
    workbook.close();
    

    You can add cells while iterating over the List<Area>. E.g.

    for (int i = 0; i < list.size(); i++) {
        Area area = list.get(i);
        sheet.addCell(new Label(0, i, area.getImgHub()));
        sheet.addCell(new Label(1, i, area.getCountry()));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this inside my DAO public String CSNSurvey() { StringBuilder mailstr = new
(Java Spring WebApp) I have: public class PersonValidator implements Validator { private PersonDAO d;
I have following code I want to test: public class MessageService { private MessageDAO
My system has this pattern DAO->Objects->facade->View so i have a DAO to query database,
I have this simple situation: @Entity public class Customer{ @ManyToMany(fetch=FetchType.EAGER) @Cascade(CascadeType.SAVE_UPDATE) private List<Product> products=new
We have the following class public class TemporalData<T> { private T data; private String
I have written a Servlet something like this public class ServletUtil extends HttpServlet {
I have this working java code that serve as the datasource: public final class
I have 2 Hibernate classes in a Spring-driven Application like these: @Entity public class
I have an abstract DAO class which uses parameterized types E (Entity) and K

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.