title: How to read value from mysql database based on condition?
body: <p>I am doing a Java project to allow users to either log in as an admin or user based on what they selected from their account creation. I managed to do a code to check if their username and password were correct in my login page of the application by checking if those values are present in the database, however, I want the user to login as either an admin or user but I don't know how to do that. Im thinking if I can read what they selected as (either user or admin) from their account creation in the database (refer below for picture of database columns), then I am able to do an if statement based on that. For example if(usertype == 'admin'){ // then go to admin page} But usertype is a column in the database which I don't know how to read.I have my code below as well which is function that activates whenever the login button is pressed.If you know of a solution, let me know thank you.</p>
  <pre><code>private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) {
      Connection con;
      PreparedStatement pst;
      ResultSet rs;                                            
          try{
              String query = &quot;SELECT * FROM `accounts` WHERE username=? and password=?&quot;; // and usertype=?
              con = DriverManager.getConnection(&quot;jdbc:mysql://localhost/restock&quot;, &quot;root&quot;, &quot;password&quot;);
              pst = con.prepareStatement(query);
              pst.setString(1, txtUsername.getText());
              pst.setString(2, txtPassword.getText());
              rs = pst.executeQuery();
              if(rs.next()){
                  
                  JOptionPane.showMessageDialog(this, &quot;Login is successful as admin&quot;);
                  mainpage admin = new mainpage();
                  admin.setVisible(true);
                  dispose();
              }
              else{
                  JOptionPane.showMessageDialog(this, &quot;Incorrect username or password&quot;);
                  /*usermainpage user = new usermainpage();
                  user.setVisible(true);
                  dispose();*/
              }
              
          } catch(Exception ex){
              JOptionPane.showMessageDialog(this, ex.getMessage());
          }
          
          
          
      }  
  </code></pre>
  <p>This is a picture of the columns that are in my database
  <a href="https://i.stack.imgur.com/RqV5m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RqV5m.png" alt="enter image description here" /></a></p>