更新:有关我所取得进展的更多信息以及我所遇到的困难,请写在 italic
的帖子末尾我正在尝试在表格视图中显示当前登录用户所做的所有约会。我正在尝试通过利用此用户登录的用户名来创建条件,因为用户名在数据库中是唯一的。
PS。我写了关于我尝试通过代码的细节。
保存约会的第一个表格如下:
这是“Programaritest”表格
ID_programare | Nume | Prenume | Data | Ora | Departament | Doctor | Nr_telefon
这是帐户表,其中用户名保存为唯一
ID_account | Username | Password | Email | Nume | Prenume | Admin
在这里,我用数据库中的东西填充tableview。
我所说的用户名在另一个类中被定义为TextField,我将在下面发布
package LicentaApp;
public class ProgramariDBController implements Initializable {
@FXML
private TableView<DetaliiProgramari> ProgrDB;
@FXML
private TableColumn<DetaliiProgramari, String> Nume;
@FXML
private TableColumn<DetaliiProgramari, String> Prenume;
@FXML
private TableColumn<DetaliiProgramari, String> Data;
@FXML
private TableColumn<DetaliiProgramari, String> Ora;
@FXML
private TableColumn<DetaliiProgramari, String> Departament;
@FXML
private TableColumn<DetaliiProgramari, String> Doctor;
@FXML
private TableColumn<DetaliiProgramari, String> Nr_telefon;
public LogareController Numeutilzator = new LogareController(); This is how I thought of taking the username which is found in LogareController, when somebody is tipying it in to login into the app.
private ObservableList<DetaliiProgramari> Info;
@Override
public void initialize(URL url, ResourceBundle ResurcesFORDAYS) {
// TODO
}
@FXML
private void loadDataFromDatabase(ActionEvent event) {
try {
ConectaredB ConectaredB=new ConectaredB();
Connection conectare=ConectaredB.logareDB();
Info = FXCollections.observableArrayList();
ResultSet IncDate = conectare.createStatement().executeQuery("SELECT * FROM programaritest WHERE Username IN (SELECT Username FROM accounts where Username='"+Numeutilzator.getText()+" ')"); This is how I thought of making the query.
while (IncDate.next()) {
Info.add(new DetaliiProgramari(IncDate.getString(2), IncDate.getString(3), IncDate.getString(4), IncDate.getString(5), IncDate.getString(6), IncDate.getString(7), IncDate.getString(8)));
}
} catch (SQLException ex) {
System.err.println("Error"+ex);
}
Nume.setCellValueFactory(new PropertyValueFactory<>("Nume"));
Prenume.setCellValueFactory(new PropertyValueFactory<>("Prenume"));
Data.setCellValueFactory(new PropertyValueFactory<>("Data"));
Ora.setCellValueFactory(new PropertyValueFactory<>("Ora"));
Departament.setCellValueFactory(new PropertyValueFactory<>("Departament"));
Doctor.setCellValueFactory(new PropertyValueFactory<>("Doctor"));
Nr_telefon.setCellValueFactory(new PropertyValueFactory<>("Nr_telefon"));
ProgrDB.setItems(null);
ProgrDB.setItems(Info);
}
}
所以这里是找到我想要使用的用户名的类:
package LicentaApp;
public class LogareController implements Initializable {
public LoginVerifier loginVerifier = new LoginVerifier();
@FXML
private TextField Numeutilzator; **This is the one, "NumeUtilizator" is the username
@FXML
private PasswordField Parola;
@FXML
private Label Stare;
@Override
public void initialize(URL location, ResourceBundle resources) {
if (loginVerifier.Conexiune()) {
Stare.setText("");
} else {
Stare.setText("Conexiune nereusita!");
}
}
public void Autentificare (ActionEvent event) {
try {
if(loginVerifier.testaredate(Numeutilzator.getText(), Parola.getText())) {
Stare.setText("Autentificare reusita !");
((Node)event.getSource()).getScene().getWindow().hide();
Stage StagePrincipala= new Stage();
FXMLLoader incarcator= new FXMLLoader();
Pane parinte = incarcator.load(getClass().getResource("/LicentaApp/Meniu.fxml").openStream());
Scene scene = new Scene(parinte);
scene.getStylesheets().add(getClass().getResource("Style1212.css").toExternalForm());
StagePrincipala.setScene(scene);
StagePrincipala.show();
}
else {
Stare.setText("Nume de utilizator sau parola incorect");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
public void Inregistrare(ActionEvent event) {
try {
((Node)event.getSource()).getScene().getWindow().hide();
Stage PS= new Stage();
FXMLLoader incarcator= new FXMLLoader();
Pane parinte = incarcator.load(getClass().getResource("/LicentaApp/InregistrareUser.fxml").open Stream());
Scene scena = new Scene(parinte);
scena.getStylesheets().add(getClass().getResource("Style1212.css").toExternalForm());
PS.setScene(scena);
PS.show();
} catch (Exception e) {
}
public String getText() {
TextField Numeutilizator = new TextField();
Numeutilizator.getText();
return null;
}
}
}
我得到的错误是:
对于LogareController类型
,方法getText()未定义
这是为什么?
PS。基本上我想显示当前登录用户所做的所有约会。
这就是我的尝试:
public String getText() {
TextField Numeutilizator = new TextField();
Numeutilizator.getText();
return null;
}
似乎已经修好了,但我不知道它应该是怎么回事,你怎么看?
将用户名添加到apointment
基本上,如果有其他人看到这个,我正在尝试从LogareController获取用户名(Numeutilizator)(用户名在那里用于登录),以便在创建apointment时在AddProgramareController中使用,用户名将被插入到表中,以便我可以使用它来显示该用户在tableview中所做的所有apoint:
我现在收到错误:
java.sql.SQLIntegrityConstraintViolationException:列'Numeutilizator'不能为null
问题是我尝试从Numeutilizator移动信息是不成功的,或者我试图将该信息提供给查询(语句)的方式并不完全存在..
package LicentaApp;
public class AddProgramareController implements Initializable {
ObservableList Timestamp=FXCollections.observableArrayList();
@FXML
private TextField Nume;
@FXML
private TextField Prenume;
@FXML
private TextField Ora;
@FXML
private DatePicker Data;
@FXML
private TextField Departament;
@FXML
private TextField Doctor;
@FXML
private TextField Nr_telefon;
@FXML
LogareController Numeutilizator=new LogareController();
public void initialize(URL location, ResourceBundle resources) {
}
@FXML
private void AddProgramare(ActionEvent event) throws SQLException, IOException {
String Interogare1= "INSERT INTO programaritest(Nume,Prenume,Data,Ora,Departament,Doctor,Nr_telefon,Numeutilizator) VALUES(?,?,?,?,?,?,?,?)";
String nume=Nume.getText();
String prenume=Prenume.getText();
LocalDate data=Data.getValue();
String ora=Ora.getText();
String departament=Departament.getText();
String doctor=Doctor.getText();
String nr_telefon=Nr_telefon.getText();
String numeutilizator=Numeutilizator.getText();
try {
ConectaredB ConectaredB=new ConectaredB();
Connection conexiune=ConectaredB.logareDB();
PreparedStatement MG = conexiune.prepareStatement(Interogare1);
MG.setString(1, nume);
MG.setString(2, prenume);
MG.setDate(3, Date.valueOf(data));
MG.setString(4, ora);
MG.setString(5, departament);
MG.setString(6, doctor);
MG.setString(7, nr_telefon);
MG.setString(8, numeutilizator);
MG.executeUpdate();
// ...
} catch (SQLException exceptie1) {
exceptie1.printStackTrace();
}
}
}