-1
我意识到这可能不是最独特的问题,但我一直试图弄清楚这个程序的语法问题,一直没有弄清楚。这里就是我得到的语法错误:Java中的语法错误(JavaFX)
});
catch
下面的代码:
public class MySQLGUI extends Application {
public void start(Stage primaryStage) {
TextField field = new TextField();
field.setPrefWidth(420);
TextField order = new TextField();
order.setPrefWidth(420);
TextField where = new TextField();
where.setPrefWidth(420);
Button button = new Button("Retrieve Records");
TextArea table = new TextArea();
table.setEditable(false);
HBox tfield = new HBox();
tfield.getChildren().addAll(new Label("Fields:"),field);
tfield.setSpacing(10);
HBox torder = new HBox();
torder.getChildren().addAll(new Label("Order:"),order);
torder.setSpacing(10);
HBox twhere = new HBox();
twhere.getChildren().addAll(new Label("Where:"),where);
twhere.setSpacing(7);
VBox top = new VBox();
top.setSpacing(10);
top.getChildren().addAll(tfield,torder,twhere,button);
FlowPane pane = new FlowPane(Orientation.HORIZONTAL);
pane.getChildren().addAll(top,table);
// Set scene
Scene scene = new Scene(pane, 480, 313);
primaryStage.setTitle("MySQLGUI"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/pcparts", "root", "password");
System.out.println("Database connected");
} catch (SQLException e) {
System.out.println("Cannot connect");
}
try {
java.sql.Statement st = conn.createStatement();
String query = "select " + field.getText();
query += " from customers";
query += " where " + where.getText();
query += " order by " + order.getText();
button.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
java.sql.ResultSet rSet = st.executeQuery(query);
while (rSet.next()) {
table.setText(rSet.getString(1) + " " + rSet.getString(2) + " " + rSet.getString(3) + " " + rSet.getString(4) + " " + rSet.getString(5) + " " + rSet.getString(6));
}
}
}
});
catch (SQLException ex) {
// handle the error
table.setText("OOPS...");
}
}
public static void main(String[] args) {
launch(args);
}
}
不起作用。括号正在关闭.setOnAction。 – dungo