gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 11:05:18 24 4
gpt4 key购买 nike

我收到消息

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

我正在遵循在线教程,但我看不出我的代码和我正在遵循的代码有什么不同。谁能指出我哪里错了?

如果需要更多信息,请告诉我。

Screenshot

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而不是原生方式

关于java - 执行更新查询时MySQL语法错误异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41514078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com