Derik_hacker

Untitled

May 1st, 2024
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.  public void login () {
  2.         PreparedStatement st=null;
  3.         ResultSet result=null;
  4.  
  5.         Connection conn=ConnexioDB.getConnexion();
  6.  
  7.         try{
  8.             st=conn.prepareStatement("SELECT * FROM users WHERE USERNAME=? AND PASSWORD=?");
  9.             st.setString(1,textfield.getText());
  10.             if(checkBox.isSelected()) {
  11.                 st.setString(2, passwordField.getText());
  12.             }else {
  13.                 st.setString(2,passwordField.getText());
  14.             }
  15.  
  16.             result=st.executeQuery();
  17.  
  18.             if(result.next()){
  19.                 Alert alert=new Alert(Alert.AlertType.CONFIRMATION,"Login successfully",ButtonType.OK);
  20.                 alert.show();
  21.             }
  22.             else {
  23.                 Alert alert =new Alert(Alert.AlertType.WARNING,"Login errore // Password o username false",ButtonType.PREVIOUS);
  24.                 alert.show();
  25.             }
  26.         }catch (Exception e){
  27.             throw new RuntimeException(e);
  28.         }
  29.     }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment