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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:20:32+00:00 2026-06-15T17:20:32+00:00

ResultSet zoeken = stat.executeQuery(SELECT * FROM leden WHERE naam = ‘ + text +

  • 0
ResultSet zoeken = stat.executeQuery("SELECT * FROM leden WHERE naam = '" + text + "'");
if (zoeken.getRow() == 0){
   System.out.println("hi");
}
while( zoeken.next() ){
   System.out.println(zoeken.getString(1) + zoeken.getString(2) + zoeken.getString(3));
}

I am using this to check if the result zoeken is empty, but it throws an exception saying its illegal to do that regardless if it works or not.

What is a better solution to check if result is empty or not

  • 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-15T17:20:33+00:00Added an answer on June 15, 2026 at 5:20 pm

    // I am using this to check if the result”zoeken” is empty, but it
    throws an exception saying its illegal to do that. regardless if it
    works or not

    Don’t invoke ResultSet.getRow() before you invoke ResultSet.next().

    From API:

    A ResultSet object maintains a cursor pointing to its current row of
    data. Initially the cursor is positioned before the first row. The
    next method moves the cursor to the next row, and because it returns
    false when there are no more rows in the ResultSet object, it can be
    used in a while loop to iterate through the result set.

           ResultSet zoeken = stat.executeQuery("SELECT * FROM leden WHERE naam = '" + text + "'");
           boolean val = zoeken.next(); //next() returns false if there are no-rows retrieved 
            if(val==false){
                System.out.println("zoken is empty"); //prints this message if your resultset is empty
             }
            while(val){// only runs when there are rows in the resultset
               System.out.println(zoeken.getString(1) + zoeken.getString(2) + zoeken.getString(3));
              val=zoeken.next(); //updating val again to check if there are rows in result set
            }
    

    If your result set is empty zoeken.next() will return false in which case your while loop will not execute.

    An Advice

    use PreparedStatement Instead of simple Statement. simple statement would lead to SQL Injection and also would ease the pain for writing complex queries.Below is the sample code which use PreparedStatement.

    String yourquery ="Select whatever From table where col1= ? and col2 =?"
    PreparedStatement stmnt = Conn.preparedStatement(yourquery);
    stmnt.setString(1, "val1");
    stmnt.setString(2, "val2");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Resultset rs=stmt.executeQuery(select count(*) from feedsca group by score order by score); Using the above
My code like this ResultSet rs = statement.executeQuery( SELECT SUM(column1) FROM table where column2=name
My ResultSet Query is StrQry = select SUM(isnull(prn_amount,0))as prn_amount,SUM(isnull(adv_prn,0))as adv_prn, SUM(isnull(prv_prn,0))as prv_prn from loan_transaction_mcg
I have the following code: ResultSet rs = DB.doQuery(SELECT username,register_ip FROM users ORDER BY
Here is my code: var resultSet; db.transaction(function (tx){ tx.executeSql('SELECT * FROM table WHERE name
from a resultset of about 5 different strings, I would like to select the
I have a ResultSet object containing all the rows returned from an sql query.
I am losing precision in my ResultSet.getDate(x) calls. Basically: rs = ps.executeQuery(); rs.getDate(MODIFIED); is
I am reading file from ResultSet and it's required to save file into Oracle
I have a resultSet that I am pulling from my database: String selStmt =

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.