Guest User

Untitled

a guest
Nov 7th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  2. String user=txtUsername.getText();
  3. char[] pass=txtPassword.getPassword();
  4.  
  5. if(user == null){
  6. JOptionPane.showMessageDialog(null,"Username Field is empty");
  7. }
  8. else if(pass==null){
  9. JOptionPane.showMessageDialog(null,"Password Field is empty");
  10. }
  11. else{
  12. String sql="select * from account where username=? and password=?";
  13.  
  14. try{
  15. pst=conn.prepareStatement(sql);
  16. pst.setString(1,txtUsername.getText());
  17. pst.setString(2,txtPassword.getText());
  18.  
  19. rs=pst.executeQuery();
  20.  
  21.  
  22. if(rs.next()){
  23.  
  24. GridlockMain a=new GridlockMain();
  25. a.setVisible(true);
  26.  
  27. }
  28.  
  29. else{
  30.  
  31. JOptionPane.showMessageDialog(null,"Your Username or Password is incorrect");
  32. txtUsername.setText(null);
  33. txtPassword.setText(null);
  34.  
  35. }
  36.  
  37. }
  38. catch(SQLException e){
  39. JOptionPane.showMessageDialog(null,e);
  40.  
  41. }
  42.  
  43. }
  44. }
  45.  
  46. String user=txtUsername.getText();// It return empty String ""
  47. // even no data is entered.
  48.  
  49. if(user.isEmpty){
  50. JOptionPane.showMessageDialog(null,"Username Field is empty");
  51. }
  52. ......
  53.  
  54. if(!user.length() > 0){
  55. JOptionPane.showMessageDialog(null,"Username Field is empty");
  56. }
  57. else if(!pass.length > 0){
  58. JOptionPane.showMessageDialog(null,"Password Field is empty");
  59. }
  60.  
  61. //Validate whether user Has input some information:
  62. if(UserNameTA.getText() == null || UserNameTA.getText().trim().isEmpty())
  63. {
  64. btnEnter.setEnabled(false);
  65. }
  66. else
  67. {
  68. //Make a new JFrame for login
  69. new ProfileHome().setVisible(true);
  70. frame.dispose();
  71. }
  72. btnEnter.setEnabled(true);
  73.  
  74. StringUtils.isEmpty(txtUsername.getText())
  75.  
  76. String user = txtUsername.getText();
  77. String pw = txtPassword.getText();
  78.  
  79. if(user.isEmpty() || (pw.isEmpty()))
  80.  
  81. {
  82. JOptionPane.showMessageDialog(null, "Your Username or Password is incorrect" );
  83. }
  84. else
  85. {
  86. //proceed to query
  87.  
  88. if (user.length() == 0) {
  89. JOptionPane.showMessageDialog(null, "Username Field is empty");
  90. } else if (pass.length() == 0) {
  91. JOptionPane.showMessageDialog(null, "Password Field is empty");
  92. }
Add Comment
Please, Sign In to add comment