Hey there fellow developers, I will need some help here. I am not sure what is wrong with my SQL syntax when I am trying to store a location of a file in my database. Here is my java code, but the problem is the actual SQL syntax.
ArrayList updates = new ArrayList();
sql = "UPDATE " + tableName + " SET " + String.join(",", updates) + " WHERE id = ?;";
System.out.println(sql);
SQLSyntaxErrorException: You have an error in your sQL syntax, check the manual that corresponds to your MariaDB server version for the right syntax to use near ':\\Users\\%Username%\\Pictures\\image_2.jpg WHERE id = 1' at line 1.
Now what comes out of this system print is my SQL query which is:
UPDATE Students SET picture = C:\Users\Student\Pictures\image_2.jpg WHERE id = ?;
So, I don't understand, what's wrong with the query syntax?
In SQL, single quotes will be escaped by using double single quotes. ' --> ''
So,Change Your query to this:
sql = "UPDATE " + tableName + " SET " + String.join(",", updates).replace("= ","= '") + "' WHERE id = ?;";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.