使用线程发出数据库请求
package application;import java.sql.ResultSet;import java.sql.SQLException;import javafx.fxml.FXML;import javafx.scene.control.Button; import javafx.scene.control.Label;import javafx.scene.control.TextField;public class Controller{ @FXML private Button getCourseBtn; @FXML private TextField courseId; @FXML private Label courseCodeLbl; private ModelController mController; private void requestCourseName(){ String courseName = ""; Course c = new Course(); c.setCCode(Integer.valueOf(courseId.getText())); mController = new ModelController(c); try { ResultSet rs = mController.<Course>get(); if(rs.next()){ courseCodeLbl.setText(rs.getString(1)); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }// return courseName; } public void getCourseNameOnClick(){ try {// courseCodeLbl.setText(requestCourseName()); Thread t = new Thread(new Runnable(){ public void run(){ requestCourseName(); } }, "Thread A"); t.start(); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
线程“Thread A”中的异常java.lang.IllegalStateException:不在FX应用程序线程上;currentThread=Thread A
慕尼黑的夜晚无繁华
HUH函数