java.sql.SQLSyntaxErrorException?

java.sql.SQLSyntaxErrorException?,sql,derby,Sql,Derby,我的代码有点问题,因为它显示了这个错误 'java.sql.SQLSyntaxErrorException:分配的值的数量与指定或隐含列的数量不同。' 我读过类似的问题,但仍然不清楚我的问题是如何显示错误的。我也试着把“像这样”放在两个值之间,但仍然没有效果。什么是事先准备好的声明 //CONNECTION Connection conn = null; try{ conn = DriverManager.getConnection("jdbc:derb

我的代码有点问题,因为它显示了这个错误

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

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()+"')");

请学习如何正确使用
PreparedStatement
,例如,通过阅读Oops my bad,在查看它这么久之后,我发现im缺少单个qoutation。。。所以应该是这样的。值(“+txtserid.getText()+”,“+txtPassword.getText()不应该。它应该是一个带有占位符的
PreparedStatement
。你不应该将用户输入连接到SQL查询是!!..啊哈我错过了一个QOUTING啊哈…谢谢你的回复