Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Node;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- public class Controller {
- @FXML TextField username;
- @FXML TextField password;
- @FXML Label warning;
- Connection c;
- PreparedStatement pst;
- ResultSet rs;
- public void loginButtonClicked() throws IOException {
- try {
- String query = "select * from Users where Username=? and Password=?";
- pst = c.prepareStatement(query);
- pst.setString(1, username.getText());
- pst.setString(2, password.getText());
- rs = pst.executeQuery();
- if (rs.next()) {
- warning.setText("Successful");
- } else {
- warning.setText("Not Successful");
- }
- } catch (Exception e) {
- System.err.println(e);
- }
- }
- public void cancelButtonClicked(ActionEvent event) throws IOException {
- System.out.println("User has cancelled login...");
- ((Node)event.getSource()).getScene().getWindow().hide();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement