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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:43:07+00:00 2026-06-05T02:43:07+00:00

Statement st=null; ResultSet rs=null; Connection con=null; String sql=select * from employee;; try{ con= new

  • 0
Statement st=null;
ResultSet rs=null;
Connection con=null;

String sql="select * from employee;";

try{

                con= new Database().getMySqlConnection();
                st=con.prepareStatement(sql);
                rs=st.executeQuery(sql);

    while(rs.next())
    {
if(rs.getInt("id")!=-1)     
{
  %>
 <tr><td align="center"><%=rs.getInt("id")%></td> 
 <td align="center"><%=rs.getString("name")%></td>
  <td align="center"><%=rs.getInt("salary")%> </td>
   <td align="center"><%=rs.getString("Designation") %></td>
}
    else
    {

        out.println("table is empty");
    } 
    }   
  }


                catch (SQLException ex) {
                    System.out.println(ex.getMessage());
                }

In this program I want to show data in table on page, by retrieving from table if not empty, if table is empty then show message or print that table is empty. But it can’t display any message, when there is data in table it works correctly.
But when table is empty the error message is not displayed.

I saw many examples on the net, perform wasNull() method , islast(), iffirst() method etc, but still problem persists.

Plz suggest the solution. This program is in java.

  • 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-05T02:43:08+00:00Added an answer on June 5, 2026 at 2:43 am

    your empty table statement should be outside the while statement. Use a flag.

    while(rs.next())
    {
        flag = 1;
        if(rs.getInt("id")!=-1)     
           {
            <tr><td align="center"><%=rs.getInt("id")%></td> 
            <td align="center"><%=rs.getString("name")%></td>
            <td align="center"><%=rs.getInt("salary")%> </td>
            <td align="center"><%=rs.getString("Designation") %></td>
           }
    }   
    if ( flag == 0 )
         out.println("Table is empty");
    

    the next() method keeps moving the cursor forward one row at a time. If you enter the while loop,it means there is something in the table.

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

Sidebar

Related Questions

my sql statement is returning null when when I compare date from access database
I have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
What code I should add to accept null from WHERE statement. { int numApprovals
Possible Duplicate: when to close Connection, Statement, PreparedStatement and ResultSet in JDBC I've written
I use the following codes to connect to Oracle's database: Connection conn = null;
I inserted one column in sql with null value from java.while retrieving back it
Is it safe to use the using statement on a (potentially) null object? Consider
I have two SQL statements: CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
Statement stmt=conn.createStatement(); //1 Statement stmt2=conn.createStatement(); //2 ResultSet resultSet1=stmt.executeQuery(-----); //3 while(resultSet1.next()) { //4 ResultSet resultSet2
SQL statement: INSERT INTO order (`ORDER_ID`,`SALE_CODE`,`CREATED_AT`,`UPDATED_AT`) VALUES ('2646253286','HPHS20','2009-07-11 12:07:40','2009-07-11 12:07:40') Error: You have an

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.