gpt4 book ai didi

java - 无法执行语句更新

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

我正在尝试执行 SQL 查询来更新数据库列中的某些数据,但是当我运行该程序时,出现以下错误:

Hibernate: update DeputeAppeal set FilePath=/home/oleg/DeputeAppealsFiles/1 where id=38
[ERROR] [http-bio-8080-exec-2 09:21:21] (SqlExceptionHelper.java:logExceptions:131) 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 '/home/oleg/DeputeAppealsFiles/1 where id=38' at line 1

这是 DAO 中的方法:

public void editFilePathName(DeputeAppeal deputeAppeal, String filePathName) {
Query query = sessionDao.getSession().createSQLQuery("update DeputeAppeal set FilePath=" + filePathName + " where id=" + deputeAppeal.getId());
query.executeUpdate();
}

最佳答案

您在查询中错过了 'filePathName' 的单引号:

Query query = sessionDao.getSession().createSQLQuery("update DeputeAppeal set FilePath=" + filePathName + " where id=" + deputeAppeal.getId());

用这个代替:

Query query = sessionDao.getSession().createSQLQuery("update DeputeAppeal set FilePath = '" + filePathName + "' where id=" + deputeAppeal.getId());

关于java - 无法执行语句更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38424565/

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