1

I need to export a Table into a CSV File and serve it to download via my JSF/Icefaces Webapplication.

How can I do that? I have a Table with 20+ Columns and over 10 MIO rows.

At the moment, I use a Java Thread, loading all data into ram. Then I create a new File and iterate the Collection writing row for row into the file. If the Thread is done, the user can download the large file via Servlet.

But I dont want to write so many GB into ram. I cant secure, not to get a memory problem..

Is it possible that hibernate does it for me? Or does somebody has an other idea?

Im connected to a DB2 Datebase. The table I want to export is connected to a hibernate bean but it is also possible to write native sql.

Thank you for response!

2 Answers 2

3

Do you need the intermediate stage of a file ? Have you tried loading from the database and writing to your servlet output stream for each row ? That way you're acting simply as a pipe between the client and the db.

Simply set your content-disposition header appropriately and that will signal the client's browser to treat the incoming data as a CSV file itself.

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

3 Comments

That`s a nice Idea. Maybe reading with an interval of 50000 datasets directly writing to response? But then I need to lock the table to prevent manipulating data?
I would expect a simple select * to be transactional. ie.. you're not going to see changes under you.
Sounds good, I think loading data with more steps is what I need. I will serve a Servlet to download the data directly and I will serve the option to save the data to a file and download the file. Then I can serve both Methods for the User. Thank you!
1

I have also gone through with similar kind of problem , the way I solve the problem is that I initially write a CSV file on disc and fetch 25K batch records from DB ans save to the file, and iteratively repeat the process until all the data required by the report is not written on the file. And then send the file URL to the client to download the file.

1 Comment

The Hibernate Batcher seems to be a rly nice option. I still use it for importing large data :) But Hibernate still has no build-in option for export to a file? With MySQL I easy could use native "LOAD FROM FILE"-Method. The DB2 Driver dont seem to support a solution like this. Thank you!

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.