Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.event.ActionEvent;
  4. import javafx.fxml.FXML;
  5. import javafx.fxml.FXMLLoader;
  6. import javafx.scene.Node;
  7. import javafx.scene.Parent;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Label;
  10. import javafx.scene.control.TextField;
  11. import javafx.scene.text.Text;
  12. import javafx.stage.Stage;
  13.  
  14. import java.io.IOException;
  15. import java.sql.Connection;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18.  
  19. public class Controller {
  20.  
  21. @FXML TextField username;
  22. @FXML TextField password;
  23. @FXML Label warning;
  24. Connection c;
  25. PreparedStatement pst;
  26. ResultSet rs;
  27.  
  28. public void loginButtonClicked() throws IOException {
  29. try {
  30. String query = "select * from Users where Username=? and Password=?";
  31. pst = c.prepareStatement(query);
  32. pst.setString(1, username.getText());
  33. pst.setString(2, password.getText());
  34. rs = pst.executeQuery();
  35.  
  36. if (rs.next()) {
  37. warning.setText("Successful");
  38. } else {
  39. warning.setText("Not Successful");
  40. }
  41.  
  42. } catch (Exception e) {
  43. System.err.println(e);
  44. }
  45. }
  46.  
  47.  
  48. public void cancelButtonClicked(ActionEvent event) throws IOException {
  49. System.out.println("User has cancelled login...");
  50.  
  51. ((Node)event.getSource()).getScene().getWindow().hide();
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement