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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:38:24+00:00 2026-06-12T05:38:24+00:00

Here is code: String sql_1 = select emp_id,password from regid; ResultSet rs = st.executeQuery(sql_1);

  • 0

Here is code:

 String sql_1 = "select emp_id,password from regid";
    ResultSet rs = st.executeQuery(sql_1);

    while(rs.next())
    {

    if(((employee.equals(rs.getString("emp_id"))) && (password.equals(rs.getString("password"))))==true)
    {

//      String sql2="update regid set regid='"+Datastore.regIds.add(regId)+"' where emp_id='"+employee+"'";
//      st.executeUpdate(sql2);
        System.out.println("2> Employee Id : "+employee+" && Password : "+password);
        System.out.println("3> This employee "+employee+" exsists in the database and registration-password id will be Updated");

    //  resp.setStatus(HttpServletResponse.SC_OK);
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();
        out.print("<html><body>");
        out.print("<head>");
        out.print("<title>Policy Page</title>");
        out.print("<link rel='icon' href='../images/favicon.png'/>");
        out.print("</head>");
        String status = (String) req.getAttribute(ATTRIBUTE_STATUS);
        if (status != null)
        {
          out.print("Status :"+status);
        }
        List<String> devices = Datastore.getDevices();
        if (devices.isEmpty())
        {
          out.print("<h2>No  devices registered!</h2>");
        } 
        else
        {

         out.print("<h2>" + devices.size() + " device(s) registered!</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>");
//       System.out.println(HTTP_STATUS);
         System.out.println(HttpServletResponse.SC_OK);
         getServletContext().getRequestDispatcher("/home").forward(req, resp);

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

    }

    else {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        System.out.println(HttpServletResponse.SC_BAD_REQUEST);
        System.out.println("4> This employee "+employee+" does not exsist in the database");            
    }

    }

//    rs.close();
    }   

But I’m getting output like,but I’m putting the correct emp_id & password(still it’s showing 4> + java.lang.illegalstateexception (don’t know why ?? 🙁 )):

1> Employee : P1 && Password : ppp
400
4> This employee P1 does not exsist in the database
2> Employee Id : P1 && Password : ppp
3> This employee P1 exsists in the database and registration-password id will be Updated
400
4> This employee P1 does not exsist in the database

any idea…..why it’s happening ?

  • 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-12T05:38:25+00:00Added an answer on June 12, 2026 at 5:38 am

    It’s happening because you algorithm consists of:

    1. Iterate through all employees
    2. If employee matches ID/password, print 2>, else print 4>

    So you’ll have one 2>, 3> output for the one that matches and all the others will give you the error 400.

    Instead, you can iterate through all your employees (although it might be best to add a criteria to your SQL to narrow down the result set by password and employee ID), don’t output an error unless you have exhausted all the results and did not find the matching one.

    PreparedStatement stmt = null;
    try {
        stmt = new PreparedStatement("select * from regis where emp_id=? and password=?");
        stmt.setString(1, employee);
        stmt.setString(2, password);
    
        ResultSet rs = stmt.executeQuery();
        if(rs.next()) {
            System.out.println("2> Employee Id : "+employee+" && Password : "+password);
            System.out.println("3> This employee "+employee+" exsists in the database and                        
            resp.setContentType("text/html");
            PrintWriter out = resp.getWriter();
            out.print("<html><body>");
            out.print("<head>");
            out.print("<title>Policy Page</title>");
            out.print("<link rel='icon' href='../images/favicon.png'/>");
            out.print("</head>");
            String status = (String) req.getAttribute(ATTRIBUTE_STATUS);
            if (status != null)
            {
              out.print("Status :"+status);
            }
            List<String> devices = Datastore.getDevices();
            if (devices.isEmpty())
            {
              out.print("<h2>No  devices registered!</h2>");
            } 
            else
            {
    
             out.print("<h2>" + devices.size() + " device(s) registered!</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>");
    //       System.out.println(HTTP_STATUS);
             System.out.println(HttpServletResponse.SC_OK);
             getServletContext().getRequestDispatcher("/home").forward(req, resp);
    
            }
            out.print("</body></html>");
            resp.setStatus(HttpServletResponse.SC_OK);
    
        }
    
        else {
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            System.out.println(HttpServletResponse.SC_BAD_REQUEST);
            System.out.println("4> This employee "+employee+" does not exsist in the database");            
        }
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    finally {
        try {
            stmt.close();
        } catch(Exception x) {}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting data from a ResultSet object. Here is my code: String
Here's the code: string name = myName; int id = (int)_myDB.ThingTable.Where(thing => thing.ThingName ==
Here is the code: string str; cin>>str; cout<<first input:<<str<<endl; getline(cin, str); cout<<line input:<<str<<endl; The
In the following code: public class A { public A():this(null){} public A(string b){/*code here*/}
I'm writing a lexer in haskell. Here's the code: lexer :: String -> [Token]
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
here is the code public static final String DATE_TIME_FORMAT = yyyy-MM-dd kk:mm:ss; public static
Here is my code : public static void main(String[] args) { // System.setProperty( //
Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
Here is my code: class Soldier { public: Soldier(const string &name, const Gun &gun);

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.