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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:19:25+00:00 2026-06-02T13:19:25+00:00

I have 3 records in my database (for testing purposes) and I am using

  • 0

I have 3 records in my database (for testing purposes) and I am using SQL_CALC_FOUND_ROWS to return the row count in conjunction with LIMIT to gather paginated results.

SELECT SQL_CALC_FOUND_ROWS * FROM contacts WHERE contacts.organizationId = :organizationId LIMIT 0, 1

I am using Spring to do my database business login as so.

public List<Contact> findAll(int organizationId, int rowStart, int rowAmount, final boolean deep) {
    final HashMap<String, Object> namedParameters = new HashMap<String, Object>();
    namedParameters.put("organizationId", String.valueOf(organizationId));
    namedParameters.put("rowStart", rowStart);
    namedParameters.put("rowAmount", rowAmount);
    final NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
    TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);

    List<Contact> contactList = transactionTemplate.execute(new TransactionCallback<List<Contact>>() {

        @Override
        public List<Contact> doInTransaction(TransactionStatus status) {
            SqlRowSet result = namedParameterJdbcTemplate.queryForRowSet(SQL_FIND_ALL_BY_ORGANIZATION_ID, namedParameters);
            int count = namedParameterJdbcTemplate.queryForInt("SELECT FOUND_ROWS()", (HashMap<String, ?>) null);
            System.out.println(count);
            List<Contact> contactList = mapContact(result, deep);
            if(contactList.size() > 0) {
                return contactList;
            } else {
                return null;
            }
        }

    });
    return contactList;
}

No matter what I do, the count comes back as 6, when I only have 3 rows in the table. In fact, it is returning 6 regardless of how many rows are in the resultset. Why is the number doubling, what I am doing wrong?

UPDATE

I ended up using this:

int count = namedParameterJdbcTemplate.queryForInt("SELECT Count(*) FROM contacts WHERE contacts.organizationId = :organizationId", namedParameters);

Basically the same as I was doing before but the SQL changed a little. I am now using count as opposed to SQL_CALC which I think results in two separate queries, but with Spring it seems to be the only way.

  • 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-02T13:19:28+00:00Added an answer on June 2, 2026 at 1:19 pm

    It looks like a side effect of using SqlRowSet. Perhaps JDBC driver issues some queries internally to support it.

    If you don’t need specific features of SqlRowSet it would be better to use more traditional approaches. For example, it would be better to use RowMapper<Contact> to query for List<Contact>.

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

Sidebar

Related Questions

I have records in the database with the sort order number. Now I want
Suppose i have 1kk records in my database. Now i need to select some
I have like 400 records on my database, suppose this is the first version
i have total 70,000 records in database. currently i displays all the records in
I have a function which calculates distance from database records. This function is called
I have an app which will generate 5 - 10 new database records in
I have stored various records in the MySql database orkut. Now I want to
I have an application with like 400 records in the database, I have splash
I want to check my database for records that I already have recorded before
I'm pretty new to SQL. I have a database with records based on road/milepoints.

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.