O.Kuz O.Kuz - 4 months ago 9
MySQL Question

could not execute statement update

I am trying to execute an SQL Query to update some data in a Database column, but when I run the program I get the following error:

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


This is the method in the DAO:

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

Answer

You missed the single quotes for 'filePathName' in your query:

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

Use this instead :

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