我看不出我搞砸了什么,还有其他人看到了什么问题吗?
我似乎无法解决这个问题,我已经在任何地方添加和删除了括号,并在我添加的每个新括号中运行
当前代码
package application;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
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.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class RegistrationController implements Initializable {
Connection connection;
public RegistrationController() {
connection = SQLConnection.Connector();
if (connection == null)
System.exit(1);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
@FXML
private TextField txtFName;
@FXML
private TextField txtSName;
@FXML
private TextField txtUName;
@FXML
private TextField txtPasswd;
@FXML
private TextField txtAge;
@FXML
private Label lblTest;
public void Submit(ActionEvent event) {
try {
String query = ("INSERT INTO member(name,surname,age,username,password) VALUES(?,?,?,?,?)");
PreparedStatement pst;
pst = connection.prepareStatement(query);
pst.setString(1, txtFName.getText());
pst.setString(2, txtSName.getText());
pst.setString(3, txtUName.getText());
pst.setString(4, txtPasswd.getText());
pst.setString(5, txtAge.getText());
pst.executeUpdate();
pst.close();
lblTest.setText("Connected");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void Back(ActionEvent event) {
try {
((Node) event.getSource()).getScene().getWindow().hide();
Stage primaryStage = new Stage();
FXMLLoader loader = new FXMLLoader();
Pane root = loader.load(getClass().getResource("/application/Login.fxml").openStream());
// ProfileController profileController =
// (ProfileController)loader.getController();
// profileController.GetUser(txtUsername.getText());
primaryStage.close();
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
答案 0 :(得分:1)
你的行应该是: -
String query = ("INSERT INTO member(name,surname,age,username,password) VALUES (?,?,?,?,?)");
请注意VALUES
关键字。