Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. private void KPA_buttonLoginActionPerformed(java.awt.event.ActionEvent evt) {
  2. {
  3. try
  4. {
  5. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  6. String url="jdbc:sqlserver://localhost:1433;databaseName=KeyProp;user=sa;password=Password1@";
  7. Connection con = DriverManager.getConnection(url);
  8. String sql = "Select * from Authentication where Username = ? and Password = ?";
  9. String usernameString = "Select * from Authentication where Username = Donovan";
  10. PreparedStatement pst = con.prepareStatement(sql);
  11. PreparedStatement usernamePst = con.prepareStatement(usernameString);
  12. pst.setString(1,KPA_tfUsername.getText());
  13. pst.setString(2,KPA_pfPassword.getText());
  14. usernamePst.setString(3,KPA_tfUsername.getText());
  15. ResultSet rs = pst.executeQuery();
  16. ResultSet usernameRs = usernamePst.executeQuery();
  17. while (usernamePst.getString(3) = 'Test')
  18. {
  19. if (rs.next())
  20. {
  21. JOptionPane.showMessageDialog(null, "Username and Password Matched");
  22. KeyProp_LaunchPage kplp = new KeyProp_LaunchPage();
  23. kplp.setVisible(true);
  24. setVisible(false);
  25. }
  26. else
  27. {
  28. JOptionPane.showMessageDialog(null, "Username and Password not Correct");
  29. KPA_tfUsername.setText("");
  30. KPA_pfPassword.setText("");
  31. KeyProp_LaunchPage kpl = new KeyProp_LaunchPage();
  32. kpl.setVisible(false);
  33. setVisible(true);
  34. }
  35. con.close();
  36. }
  37. }
  38. catch(Exception e)
  39. {
  40. JOptionPane.showMessageDialog(null, e);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement