无法执行语句更新

时间:2016-07-17 18:28:03

标签: java mysql hibernate

我正在尝试执行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();
    }

1 个答案:

答案 0 :(得分:1)

您错过了查询中'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());
相关问题