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 7853375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:40:07+00:00 2026-06-02T19:40:07+00:00

We have a web application where users can download a list of data by

  • 0

We have a web application where users can download a list of data by clicking a link. What that does is fires a stored proc in a MS sql server db – fetches rows with 14 columns and all Strings. Once we get that and extract from the resultset we directly stream it down to a csv file on teh client’s machine. That way we are saving creating intermediate domain objects(equal to number of rows retuned) in memory before starting the streaming operation. Also we donot wait until the whole resultset has been loaded in memory.
However say for clients who has e..g 80000 instances of such data – it is still spiking up the memory by 50 mb – then there is a fall of around 20 mb and it remains at that level for quite sometime. If I do a Perform GC on jconsole it frees the remaining 30 mb as well. Not sure what is causing that to linger for sometime. Also the 50 mb spike is unnacceptable for a application running on 1.2 gig memory. for bigger clients it shots up by 400 mb and freezes the application or OOM happens.
Any suggestion how we can achieve this?
PLEASE note – I have implemented teh same thing in another place and there is downloads a file of same size but different data(6 columns) in 5 secs and with a memory spike of only 5 mb. In this case it took the stored proc to run in only 4 secs though when run on Sql Mnagament studio. But the one for which i am getting a huge spike the query itself takes 45 secs to run and more based on data as it passes it through a lot of validation. Can that have an adverse effect? I was hoping not as we are fetching chunks of 1000 on the setFetchSize() on the preparedststement

here is the snippet of code

Connection connection = null;
        PreparedStatement statement = null;
        ResultSet rs = null;
        OutputStream outputStream = null;
        BufferedWriter bufferedWriter = null;
        try
        {
            response.setContentType("application/save");
            response.setHeader("Content-Disposition", "attachment; filename="
                    + link.getFileName());

            outputStream = response.getOutputStream();

            bufferedWriter = new BufferedWriter(new OutputStreamWriter(
                    outputStream));

            connection = dataSource.getConnection();
            statement = connection.prepareStatement(link.getQuery());

            statement.setFetchSize(1000);
            statement.setInt(1, form.getSelectedClientId());

            rs = statement.executeQuery();

            while (rs.next())
            {

                bufferedWriter
                        .write(getCsvRowString(new String[]
                        { rs.getString(1), rs.getString(2), rs.getString(3),
                                rs.getString(4), rs.getString(5),
                                rs.getString(6), rs.getString(7),
                                rs.getString(8), rs.getString(9),
                                rs.getString(10), rs.getString(11),
                                rs.getString(12), rs.getString(13),
                                rs.getString(14), rs.getString(15),
                                rs.getString(16), rs.getString(17),
                                rs.getString(18) }));

            }

        } catch (final Exception e)
        {
            log.error("Error in downloading extracts " + e.getMessage());
            throw e;
        } finally
        {
            if (bufferedWriter != null)
            {
                bufferedWriter.flush();
                bufferedWriter.close();
            }
            if (outputStream != null)
            {
                outputStream.close();
            }

            rs.close();
            statement.close();
            connection.close();
        }
  • 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-02T19:40:08+00:00Added an answer on June 2, 2026 at 7:40 pm

    Probably the ancient MS SQL JDBC driver is ignoring the setFetchSize() hint (see this answer https://stackoverflow.com/a/1982109/116509). Try using the jTDS driver like on Horizon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that allows users to build a 'client list.' We
I have a web application that shows a users all of their data bucketed
I have a web application in which one of the workflows, users can download
I want to build a web application where users can register and have a
I have an interactive web application powered by jQuery where users can manipulate visual
I have a web application with users and their documents. Each user can have
I have a web application that can load plugins through reflection. It currently uses
I have a web application that allows users to create an account, and in
We have JSF web application that generates XLS file and gives user link to
I have a winform application that uses some referenced web services to get data.

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.