Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 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. String user=txtUsername.getText();// It return empty String ""
  44. // even no data is entered.
  45.  
  46. if(user.isEmpty){
  47. JOptionPane.showMessageDialog(null,"Username Field is empty");
  48. }
  49. ......
  50.  
  51. if(!user.length() > 0){
  52. JOptionPane.showMessageDialog(null,"Username Field is empty");
  53. }
  54. else if(!pass.length > 0){
  55. JOptionPane.showMessageDialog(null,"Password Field is empty");
  56. }
  57.  
  58. txtUsername.getText().equals("");
  59.  
  60. if (user.length() < 0) {
  61. JOptionPane.showMessageDialog(null,"Username Field is empty");
  62. }
  63. else if(pass.length() < 0) {
  64. JOptionPane.showMessageDialog(null,"Password Field is empty");
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement