gpt4 book ai didi

java - [Microsoft][ODBC Microsoft Access 驱动程序] 查询表达式中存在语法错误(缺少运算符)

转载 作者:太空宇宙 更新时间:2023-11-04 13:38:52 26 4
gpt4 key购买 nike

需要有关 JAVA 更新查询的帮助,刚刚开始学习但遇到问题

执行时出现以下错误

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'B.AWHERE ID =4'.

MS Access 数据库文件中的数据未更新

public void update(Student s)
{
int w = Integer.parseInt(s.getID());

String query = "UPDATE Student SET ID =" + w + "," + "FirstName =" + s.getFirstName() + "," + "LastName =" + s.getLastName() + "," + "Address =" + s.getAddress() + "," + "Gender =" + s.getGender() + "," + "DOB =" + s.getDOB() + "," + "Degree =" + s.getDegree() + "WHERE ID =" + w;

try
{
stmt.executeUpdate(query);
}
catch(SQLException e)
{
System.out.println("Problem in Query");
e.printStackTrace();
}
}

最佳答案

将您的 UPDATE 语句更改为如下所示

String query = "UPDATE Student SET "FirstName = '" + s.getFirstName() + 
"'," + "LastName = '" + s.getLastName() +
"'," + "Address = '" + s.getAddress() +
"'," + "Gender = '" + s.getGender() +
"'," + "DOB = '" + s.getDOB() +
"'," + "Degree = '" + s.getDegree() +
"' WHERE ID = " + w;

但是您的查询没有多大意义,因为您正在设置 ID = w 并检查 WHERE ID = w

关于java - [Microsoft][ODBC Microsoft Access 驱动程序] 查询表达式中存在语法错误(缺少运算符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31419444/

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