title: How to check if username already exist in the sql database before one can create new account using java
body: <p>How can i put into code when i want to prompt a message whenever a user creates a new account or updates his/her username and that username already exist on the sql database.
   here's a part of my code when i click save button on my CreateNewUserAccount class:</p>
  
  <pre><code>   String sql = "insert into tblUserInfo (UserID, LastName, FirstName, PositionID, Username, Password) values(?, ?, ?, ?, ?, ?) " ;
      try{
          pst = conn.prepareStatement(sql);
          pst.setString(1, txtUserID.getText());
          pst.setString(2, txtLastName.getText());
          pst.setString(3, txtFirstName.getText());
          pst.setString(4, (String) comboPosition.getSelectedItem().toString().substring(0, 1));
          pst.setString(5, txtUsername.getText());
          pst.setString(6, txtPassword.getText());
          pst.execute();
          if(txtConfirmPassword.getText().equals(txtPassword.getText())){
          JOptionPane.showMessageDialog(null, "Saved New User Account");
          clear();
          }
          else{
            JOptionPane.showMessageDialog(null, "Incompatible Password");
            txtConfirmPassword.setText("");
          }
          //UpdateEmployeeTable();
      }catch(Exception e){
          JOptionPane.showMessageDialog(null, e);
      }
  </code></pre>
  
  <p>and also my UserAccount class where user can update/edit their information including their username:</p>
  
  <pre><code>  String sql = "update tblUserInfo set LastName = ?, FirstName = ?, PositionID = ?, Username = ?, Password = ? where UserID= ?";
  
   try {
      pst = conn.prepareStatement(sql);
  
      pst.setString(1, txtLastName.getText());
      pst.setString(2, txtFirstName.getText());
      pst.setString(3, (String) comboPos.getSelectedItem().toString().substring(0, 1));
      pst.setString(4, txtUserName.getText());
      pst.setString(5, txtPassword.getText());
      pst.setString(6, txtUserID.getText());
      pst.executeUpdate();
      JOptionPane.showMessageDialog(null, "User Account Updated");
  
  } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, e);
  }
  </code></pre>
  
  <p>how can i put a checking on this? Thanks in advance</p>