【发布时间】:2017-10-18 08:25:19
【问题描述】:
我看不到我搞砸了什么,还有其他人看到问题吗?
我似乎无法弄清楚这是怎么回事,我已经在所有可能的地方添加和删除了括号,并使用我添加的每个新括号运行
当前代码
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();
}
}
}
【问题讨论】:
-
再次投票者可以提供反馈,这样我就可以解决我的问题,而不是投票和消失
-
应该是
insert into.. values ..。 SQL 无效,因此出现错误 -
试试
...) VALUES (...而不是...) (...? -
我的坏人,添加了值,在发布后 30 秒注意到,没有错误,标签显示为“已连接”,就像代码中一样,但数据库中没有更新 @VeeraKannadiga
-
也许你可以发一个minimal reproducible example。