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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:30:09+00:00 2026-05-24T18:30:09+00:00

I am hitting my database and getting a ResultSet that tells me the current

  • 0

I am hitting my database and getting a ResultSet that tells me the current row # is 2 with a call to getRow(), but that fails to loop when I call the next() method:

// Doesn't even loop once; fails on initial next() call -- entire loop skipped
try
{
    ResultSet oResults = executeSQL("SELECT * FROM widgets");

    // Returns a value of 2
    int iRowCount = oResults.getRow();

    if(iRowCount == 0)
        return;

    while(oResults.next())
    {
        // Never gets executed
    }

    // This gets executed though, and all the way down...
    // ...
}
catch(Exception e) { handleException(e); }

I’ve spent nearly an hour this morning trying to figure out what’s happening, but this is the literal code that I am trying to execute (it’s a test/sandbox project, so it might not make logical sense). This ever happen to anybody?

  • 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-05-24T18:30:10+00:00Added an answer on May 24, 2026 at 6:30 pm

    The standard JDBC libraries return a ResultSet that has no clue as to how many rows are in it. Unless your implementation of executeSQL returns a CachedRowSet (which essentially has pre-scrolled through the result set and loaded all rows into memory), you’ll never know the number of rows until you hit the end when oResults.next() returns false.

    Thus your attempt at controlling program flow by checking the row count will never work.

    Next, your call to ResultSet.getRow() is also probably useless. Here’s what the javadoc says:

    Retrieves the current row number. The first row is number 1, the second number 2, and so on.
    Note: Support for the getRow method is optional for ResultSets with a result set type of TYPE_FORWARD_ONLY

    Most implementations from JDBC drivers are forward only (ie you can’t scroll backwards via the previous() method), so the result of getRow() is probably not useful.

    Here’s what your code should look like:

    ResultSet oResults = executeSQL("SELECT * FROM widgets");
    
    while(oResults.next())
    {
        // Process rows
    }
    

    If you are still not getting into the while loop, it means your query is returning no rows – there’s no other explanation. If getting no rows is “impossible”, then I suggest you check your connection parameters to make sure you’re connecting to the correct database (and not to localhost for example).

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

Sidebar

Related Questions

I have a Sinatra DataMapper app hitting a sqlite3 database that I am attempting
I've got some Excel spreadsheets that are hitting the database pretty hard (100+ queries
I'm currently trying to optimize an database by combining queries. But I keep hitting
I'm finding that hitting the Refresh button on my browser will temporarily screw up
I have a page that is hitting a webservice every 5 seconds to update
I have an application that needs to constantly (every 50ms), call to an MVC
I'm hitting the DB for a 100 records from a MySQL DB that have
I have a method that calls two other methods in it. def main_method(self, query):
I have an oracle 11g database. As I understand it, but have not tried
As best I can tell cucumber is only hitting the database once between these

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.