0
查看下面的代碼。不顯示警告消息
void viewStudent() throws ClassNotFoundException, SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
connect2 = DriverManager
.getConnection("jdbc:mysql://localhost:3306/project?"
+ "user=root&password=virus");
statement2 = connect2.createStatement();
preparedStatement2 = connect2
.prepareStatement("select regno from student where regno= "
+ ""+Integer.parseInt(txt1.getText())+"");
resultSet2 = preparedStatement2.executeQuery();
checkRegno(resultSet2);
} catch (ClassNotFoundException | SQLException e) {
throw e;
} finally {
close1();
}
}
void checkRegno(ResultSet resultSet2) throws SQLException {
while (resultSet2.next()) {
int trno = Integer.parseInt(resultSet2.getString("regno"));
int regno = Integer.parseInt(txt1.getText());
if (trno == regno) {
resultSet2 = statement2
.executeQuery("select * from student where regno= " + regno + "");
writeResultSet(resultSet2);
}
else {
final Text warning = new Text("Register Number Not Found...!");
warning.setFill(Color.RED);
warning.setStyle("-fx-font: 18 arial;");
Stage dialogStage = new Stage();
dialogStage.setTitle("Warning");
dialogStage.initStyle(StageStyle.UTILITY);
dialogStage.setScene(new Scene(VBoxBuilder.create().
children(warning).alignment(Pos.CENTER).
padding(new Insets(25, 25, 25, 25)).build()));
dialogStage.show();
}
}
}
我在數據庫中有一個名爲'學生'的表。當「if(trno == regno)」爲真時,「writeResultSet(resultSet2);」工作正常。當它爲假時,其他部分不起作用。我該如何解決這個問題?
我沒有使用任何線程。上面的代碼是什麼意思? – TomJ
應該從「JavaFX Application Thread」調用所有的UI操作,上面的調用確保。 –
我將它包含在'其他'中。它不工作仍然。現在做什麼 ? – TomJ