gpt4 book ai didi

java - 如何通过DAO更新mysql中实体的ID?

转载 作者:行者123 更新时间:2023-12-02 02:25:54 26 4
gpt4 key购买 nike

//这是我的 AccountDAO 中的代码

@Override
public void editAccount(Accounts account) throws ErrorException {

response = FAILED;
Connection connection = null;
PreparedStatement pStatement = null;
String sql = "UPDATE all_accounts SET
accountID=?,accPassword=?,accStatus=?"
+ "WHERE accountID "+ account.getAccountID();
ResultSet resultSet = null;
try {
if(manager == null){
manager = (DBManager)
DBManagerImplementation.getInstance();
}

connection = manager.getConnection();
pStatement = connection.prepareStatement(sql);

pStatement.setString(1, account.getPassword());
pStatement.setString(2, account.getStatus());

pStatement.execute();
} catch (SQLException ex) {
System.out.println("Error in editng/adding new
employee!!"+ex.toString());

}catch (Exception ex) {
System.out.println("Erroorr. super error!!"+ex.toString());
} finally{
DataDispatcher.dispatch(resultSet, pStatement, connection);
}
}

但是编译后这是我的错误:

Error in editng/adding new employee!!com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '111' at line 1

最佳答案

这就是您的查询的样子

"UPDATE all_accounts SET 
accountID=?,accPassword=?,accStatus=?"
+ "WHERE accountID "+ account.getAccountID();

有几个突出的事情

  • WHERE 子句之前没有空格
  • 没有为 WHERE 子句赋值,即

WHERE accountID ="+ account.getAccountID();

关于java - 如何通过DAO更新mysql中实体的ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47766923/

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