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

  • SEARCH
  • Home
  • 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 9168909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:44:38+00:00 2026-06-17T15:44:38+00:00

Problem I have now is that the stored procedure called by the jdbcTemplate returns

  • 0

Problem I have now is that the stored procedure called by the jdbcTemplate returns large amount of records, million records, which make our java query method very slow.

My java query method does the paging of the results so it is very slow. How can I improve this without altering the DB stored procedure. That is, to query for specific rows only so the java method would not have the burden of processing million records to do the paging.

public PageModel<Map<String, String>> query(String sql, final int offset, final int limit) throws ReportException {
    try {
        return jdbcTemplate.query(sql, new ResultSetExtractor<PageModel<Map<String, String>>>() {
            @Override
            public PageModel<Map<String, String>> extractData(ResultSet rs)
                    throws SQLException, DataAccessException {
                long startTime = System.nanoTime();
                PageModel<Map<String, String>> pageModel  = new PageModel<Map<String,String>>();
                List<Map<String, String>> list = new ArrayList<Map<String,String>>();
                int rows = 0;
                // skip rows
                for (int i=0; i<offset&&rs.next(); i++) {
                    rows++;
                }
                // get rows
                for (int i=0; i<limit&&rs.next(); i++) {
                    Map<String, String> map = new HashMap<String, String>();
                    ResultSetMetaData metadata = rs.getMetaData();
                    int count = metadata.getColumnCount();
                    for (int j=1; j<=count; j++) {
                        map.put(metadata.getColumnName(j), rs.getString(j));
                    }
                    list.add(map);
                    rows++;
                }
                // iterate remaining rows to get total rows
                while (rs.next())
                    rows++;
                pageModel.setOffset(offset);
                pageModel.setLimit(limit);
                pageModel.setData(list);
                pageModel.setTotal(rows);
                long endTime = System.nanoTime();
                long duration = endTime - startTime;
                System.out.println("Query took: " + duration);
                return pageModel;
            }
        });
    } catch (DataAccessException e) {
        throw new ReportException(e);
    }
}
  • 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-17T15:44:39+00:00Added an answer on June 17, 2026 at 3:44 pm

    How can I improve this without altering the DB stored procedure.

    There is no any solution in your case, only altering SP

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

Sidebar

Related Questions

I have a Stored Procedure which right now returns a (potentially) large data set.
Hi Stackoverflow super stars... Here's my problem. I have a stored procedure that outputs
I have created a stored procedure GetNotifications that returns all notifications for a specific
I have a stored procedure that returns a value, not a dataset, and I
This is stored procedure that worked on earlier version of mysql. Now, I have
I have a stored procedure that adds an object to the database and returns
I have a problem that I'm working on for quite some time now. I
I have a problem that I had working in a test but now in
I have a small problem that takes me for a day and until now
I have a dynamic list code that works just fine. My only problem now

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.