繁体   English   中英

执行更新查询时,MySQL语法错误异常

[英]MySQL Syntax Error Exception when executing Update query

我收到消息

"MySQLSyntaxErrorExcetpion You have an error in your SQL syntax."

我正在关注在线教程,但看不到我的代码和所关注的代码有什么不同。 谁能指出我哪里出问题了?

让我知道是否需要其他信息。

屏幕截图

btn_update.addActionListener(new ActionListener(){


            @Override
            public void actionPerformed(ActionEvent e) {

                try{
                    theQuery("update users set fname = '" + firstNameField.getText() + "', lname = '" + lastNameField.getText() +"', age=" + ageField.getText() + "where id = " + idField.getText());
                }
                catch(Exception ex)
                {
                    System.out.println(ex);
                    }

            }
        });

因为您在这里没有空格:

age=" + ageField.getText() + "where id = " + idField.getText());

您需要将其更改为

age= " + ageField.getText() + " where id = " + idField.getText());

我建议使用PreparedStatement而不是本机方式

在“ where id =”前面添加一个空格。 那应该工作

使用toString()函数将值转换为字符串,然后将其传递给查询,如下所示:

firstNameField.getText().toString()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM