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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:54:53+00:00 2026-06-12T02:54:53+00:00

Actually I’m facing logical problem in this code Issue : While I’m putting the

  • 0

Actually I’m facing logical problem in this code

Issue : While I’m putting the right emp_id and password,the if portion is running properly,but within this if condition whenever I’m trying to running this page(Run as->Run on Server-Tomcat server)….it’s going to the else condition-which makes me unable run the jsp page whithin the if clause.

              else {
              resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);

                          }

I want to run the jsp page aswell when it satisfy the if clause.

Here is my code:

     try {
          String url="jdbc:mysql://localhost/app";
          Class.forName("com.mysql.jdbc.Driver");
          Connection con=DriverManager.getConnection(url,"****","******");
          stmt = con.prepareStatement("select * from ofc where emp_id=? and password=?");
          stmt.setString(1, employee);
          stmt.setString(2, password);

          ResultSet rs = stmt.executeQuery();

          if(rs.next()) {  //I want to print this jsp page for this If condition
              System.out.println("2> Employee Id : "+employee+" && Password : "+password);
              System.out.println("3> This employee "+employee+" exsists in the database and will be there");      

              resp.setContentType("text/html");
              PrintWriter out = resp.getWriter();
              out.print("<html><body>");       // It's my JSP page,& start from here
              out.print("<head>");
              out.print("<title>Policy Page</title>");
              out.print("</head>");
              List<String> devices = Store.getDevices();
              if (devices.isEmpty())
              {
                out.print("<h2>No  One is there!</h2>");
              } 
              else
              {    
               out.print("<h2>" + devices.size() + " device(s) are there!</h2>");
               out.print("<form name='form' method='POST' action='sendAll'>");
               out.print("<input type='text' name='policy'>");
               resp.setStatus(HttpServletResponse.SC_OK);
               out.print("<input type='submit' value='Apply Policy'>");
               out.print("</form>");
//             getServletContext().getRequestDispatcher("/home").forward(req, resp);

              }
              out.print("</body></html>");       //Completes here
              resp.setStatus(HttpServletResponse.SC_OK);

          }


          else {
              resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);

                          }
      }
      catch(Exception e) {
          e.printStackTrace();
      }

Where I’m going wrong….in this coding context …//

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

    When you debug your code, does the debugger go into the IF statement – actually enter within the inner brackets of the IF statement, or does it merely evaluate the IF statement, (evaluate at it to “IF(False)”) and then move on to the else statement?

    Maybe your mySQL query doesn’t return any results? Try using the HasRows property.

    if (rs.HasRows) 
    { 
        while (rs.Read()) 
        { 
            // do stuff
        } 
        } 
        else 
        { 
           // notify user that query returned no results
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually I don't know how to find solution to this problem and how to
actually I can not find an exact title for this problem. But I can
Actually this is a classic problem as SO user Victor put it (in another
Actually, I am facing a problem in Android. I am creating an application that
Actually this is my code: echo <pre>; // get current vars $p1 = isset($_GET['p1'])
Actually I don't know how to define this idioms. In some code i have
Actually, this is my problem. I have a rails app with a MainController, a
Actually i am facing a problem calling a stored procedure and making some changes
Actually I am working on this for the last 3 or 4 weeks but
Actually I am stuck in middle of some mysql code. Can anyone suggest a

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.