java.sql.SQLSyntaxErrorException?

时间:2017-09-20 04:11:14

标签: sql derby

我的代码有点麻烦,因为它显示此错误

'java.sql.SQLSyntaxErrorException:分配的值的数量与指定或隐含列的数量不同。'

我读过类似的问题,但仍然对我的如何仍然显示错误感到困惑。我也尝试在这些值之间加上“,”,但仍然没有好处。什么是准备好的声明?

    //CONNECTION
    Connection conn = null;
    try{
    conn = 
    DriverManager.getConnection("jdbc:derby://localhost:1527/MetroEventsDB", 
    "root", "root");
    System.out.println("Connected");

    //Insertion
    Statement stmt = (Statement) conn.createStatement();
    stmt.execute("INSERT INTO Users(UserID, Password, FirstName, LastName, Gender, Birthdate) VALUES('"+txtUserID.getText()+txtPassword.getText()+txtFirstName.getText()+txtLastName.getText()+gender+txtBirthdate.getText()+"')");
    }catch(SQLException e){
            System.err.println(e);
            }

1 个答案:

答案 0 :(得分:1)

stmt.execute中存在语法错误。正确的语法是,

 stmt.execute("INSERT INTO Users(UserID, Password, FirstName, LastName, Gender, Birthdate) VALUES('"+txtUserID.getText()+"','"+txtPassword.getText()+"','"+txtFirstName.getText()+"','"+txtLastName.getText()+"','"+gender+"','"+txtBirthdate.getText()+"')");