Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. class loginButton implements ActionListener{
  2.  
  3. public void actionPerformed(ActionEvent e) {
  4. Connection connection;
  5. PreparedStatement ps;
  6. try {
  7. connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/userlist", "root", "Hadasada3!");
  8. ps = connection.prepareStatement("SELECT `username`, `password` FROM `userlist` WHERE `username` = ? AND `password` = ?");
  9. ps.setString(1, textUsername.getText());
  10. ps.setString(2, String.valueOf(textPassword.getPassword()));
  11. ResultSet result = ps.executeQuery();
  12. if(result.next()){
  13. JOptionPane.showMessageDialog(null, "Login Success.");
  14. String[] args = null;
  15. CowboyCorral.main(args);
  16. dispose();
  17. }
  18. else{
  19. JOptionPane.showMessageDialog(null, "Login Failed.");
  20. }
  21. } catch (SQLException ex) {
  22. Logger.getLogger(CCLogin.class.getName()).log(Level.SEVERE, null, ex);
  23. }
  24. }
  25. }
  26. buttonLogin.addActionListener(new loginButton());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement