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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:12:14+00:00 2026-06-15T07:12:14+00:00

Observing a strange behavior of this piece of code,because resultset is not giving the

  • 0

Observing a strange behavior of this piece of code,because resultset is not giving the null value(doing SOP it’s clear)but not going into while loop(that is quite strange!)and it’s simple dao class,it’s not able to set the value in user object:

public class DAO{

 public List<User> searchAllUsers(int offset ,int noOfRecords, String column, String value){
    String query="select SQL_CALC_FOUND_ROWS * from info where '"+column+"' like '%"+value+"%' order by serialNo asc limit " + offset + "  ,  " + noOfRecords;
    //  String query="select * from info where '"+select+"' like '%"+search+"%' order by serialNo asc";
    System.out.println("1");
    List<User> list = new ArrayList<User>();
    User user=null;

    try {
        System.out.println("b4 Connection");
        connection = getConnection();
        System.out.println("After Connection");
        stmt = connection.createStatement();
        System.out.println("Create statement");
        ResultSet rs=stmt.executeQuery(query);
        if(rs!=null)
        System.out.println("1> Hi rs:"+rs);
        while(rs!= null && rs.next()){
            System.out.println("hi...!!");
            user=new User();
            user.setSerial(rs.getInt(1));
            System.out.println("Serial : "+rs.getInt(1));
            user.setName(rs.getString(2));
            user.setEmail(rs.getString(3));
            user.setImei(rs.getString(4));
            System.out.println("I'm here !");
            user.setModel(rs.getString(5));
            user.setManufacturer(rs.getString(6));
            user.setOsversion(rs.getString(7));
            user.setHdyk(rs.getString(8));
            user.setDate(rs.getString(9));
            user.setAppname(rs.getString(10));
            list.add(user);
            System.out.println("Last..");
            }
        rs.close();
        rs = stmt.executeQuery("SELECT FOUND_ROWS()");
        System.out.println("2> :" +rs);
        if(rs.next()){
            this.noOfRecords = rs.getInt(1); 
        System.out.println("3> :" +this.noOfRecords);
        }
        rs.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
      finally
    {
        try {
            if(stmt != null)
                stmt.close();
            if(connection != null)
                connection.close();
            } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    return list;

}

public int getNoOfRecords() {
    return noOfRecords;
}
}

And it corresponding output is :

1
b4 Connection
After Connection
Create statement
1> Hi rs:com.mysql.jdbc.JDBC4ResultSet@35e6e3
2> :com.mysql.jdbc.JDBC4ResultSet@c9630a
3> :0

Even I’m also using the same code like it for select All user’s and that point of time I’m getting proper o/p.

Spending so many hours for it,but unable to resolve it-where I’m going wrong….so your review & comment will be always welcome.

  • 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-15T07:12:15+00:00Added an answer on June 15, 2026 at 7:12 am

    That’s because your query didn’t fetch you any row. And hence rs.next() will return false, hence the execution will not go into the while loop:

    while(rs!= null && rs.next())
    

    And you don’t have to check for rs != null. It won’t be null. The stmt.executeQuery always returns a ResultSet. Just have rs.next() in your while:

    while(rs.next())
    

    And yes, you should use PreparedStatement for executing your query rather than Statement. Here’s a tutorial which will help you get started.

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

Sidebar

Related Questions

Using OneNote 2010 doing some C# interop stuff. Observing some very strange behavior, which
I'm observing some strange behavior in my code and I'm trying to track down
Observing rather strange behavior in relative layout. This is the initial state: Defined as:
I am observing strange behaviour of std::map::clear(). This method is supposed to call element's
I'm observing some strange behavior with a local variable within a nested for loop
I'm observing some strange behavior when using the F# interactive interpreter. Running the following
I'm observing a strange behavior in a VisualForce page. I defined a css class
’m observing a strange behavior from my application which I hope you can explain
I'm observing a strange behavior scheduling a job in Quartz using a CronTrigger that
I am observing a strange bug in some of my code which I suspect

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.