私はJavaをもう少し学びたいと思っているので、私が作ったばかりのjavafxアプリケーションがあります。私はログインシステムに取り組んでいます。私が持っている問題は、ユーザーに彼または彼女の姓と彼の姓を使ってログインさせたいということです。複数のテーブルからのJavaFXログインシステム
フライト番号は「フライト」と呼ばれるテーブルにあり、ラストネームは「乗客」というテーブルにあります。私はユーザー名とパスワードが同じテーブルにあるログインシステムを作る方法を知っています。しかし、私はどのように2つの異なるテーブルからのデータでこれを行うか分からない。
誰かが私を助けることができたら大好きです!
CODE:
package databasetesten;
import databasetesten.connection.ConnectionUtil;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
/**
*
* @author Matt Holland
*/
public class FXMLDocumentController implements Initializable {
@FXML
private TextField textEmail;
@FXML
private PasswordField textPassword;
Stage dialogStage = new Stage();
Scene scene;
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
public FXMLDocumentController() {
connection = ConnectionUtil.connectdb();
}
@FXML
private void handleButtonAction(ActionEvent event) {
String email = textEmail.getText().toString();
String password = textPassword.getText().toString();
String sql = "SELECT * FROM Employee WHERE username = ? and password = ?";
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, email);
preparedStatement.setString(2, password);
resultSet = preparedStatement.executeQuery();
if (!resultSet.next()) {
infoBox("Enter Correct Email and Password", "Failed", null);
} else {
infoBox("Login Successfull", "Success", null);
Node source = (Node) event.getSource();
dialogStage = (Stage) source.getScene().getWindow();
dialogStage.close();
scene = new Scene(FXMLLoader.load(getClass().getResource("FXMLMenuEmployee.fxml")));
dialogStage.setScene(scene);
dialogStage.show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void infoBox(String infoMessage, String titleBar, String headerMessage) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(titleBar);
alert.setHeaderText(headerMessage);
alert.setContentText(infoMessage);
alert.showAndWait();
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
これは私が私の現在のログインのために持っているものです。そして、これはうまく動作します。
データベースは次のようになります。 データベース名:空港
表:飛行
flightnumber IATA Timezone
ENG456HNJ AMS 1
表:乗客
firstname lastname
Bob Smith
だから私は私の質問があると思います。乗客が飛行機番号と姓でログインできるようにするにはどうすればよいですか? 2つの異なるテーブルのデータ?
ログインに成功すると思われるものを判断するための実際の論理は何ですか? –
私は誤っていないとすれば、ユーザーは同じパスワードを使用して航空便番号または姓でログインできるようにしたいと考えている – Vanguard
乗客が最初のテキストボックスに飛行場番号を入力し、その姓が2番目テキストボックス。あなたは飛行番号がユーザ名でパスワードは乗客の姓であると言うことができます – Snidjers