SQLite插入语句:SQL错误或缺少数据库(接近“(”:语法错误)

时间:2022-02-09 01:29:19

I can't see what I've messed up, is anyone else seeing an issue?

我看不出我搞砸了什么,还有其他人看到了什么问题吗?

I can't seem to work out whats the matter, I've added and removed brackets everywhere possible and ran with each new bracket it I added

我似乎无法解决这个问题,我已经添加并删除了任何可能的括号,并添加了我添加的每个新括号

Current code

    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();
        }
    }


}

1 个解决方案

#1


1  

Your line should be:-

你的行应该是: -

String query = ("INSERT INTO member(name,surname,age,username,password) VALUES (?,?,?,?,?)");

Note the VALUES keyword.

请注意VALUES关键字。

#1


1  

Your line should be:-

你的行应该是: -

String query = ("INSERT INTO member(name,surname,age,username,password) VALUES (?,?,?,?,?)");

Note the VALUES keyword.

请注意VALUES关键字。