简体   繁体   中英

SQL Syntax error a or near

I have a sql problem.
My problem is that one of my statement doesn't work for an unknowned reason. It seems stupid but I can't understand why.

statement.executeUpdate("INSERT INTO calamar.calamar.derogationlinuxexecution (id, chemin, user, serveur, justificatif) " 
+ " VALUES ('"+id+"', '"+chemin+"', '"+user+"', '"+serveur+"', '"+justificatif+"');");

I got that error: org.postgresql.util.PSQLException: ERROR: syntax error at or near « user »

I've tryed to System.out.println my request and I got:

INSERT INTO calamar.calamar.derogationlinuxexecution (id, chemin, user, serveur, justificatif)  VALUES ('35', '/etc/pssw', 'm421339', 'qviP153', 'jusitifcation de ouf');

I really don't understand where am I wrong. When I delete the "user," and "m421339," it work with no problem.

user is a reserved word for postgresql , so the parser is getting confused by the column name.

You can either re-name the column to something non-reserved ("username" is popular for this), or you can wrap the column name in double quotes:

INSERT INTO calamar.calamar.derogationlinuxexecution
  (id, chemin, "user", serveur, justificatif)
  VALUES
  ('35', '/etc/pssw', 'm421339', 'qviP153', 'jusitifcation de ouf');

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM