-1

I'm trying to write some records on an empty MySQL table defined with the CREATE STATEMENT structure below:

CREATE TABLE `table_1` (
  `full_name` varchar(45) DEFAULT NULL,
  `gender` varchar(45) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `birthdate` datetime DEFAULT NULL,
  `email` varchar(45) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `mobile_phone` varchar(45) DEFAULT NULL,
  `entry` varchar(255) DEFAULT NULL,
  `lat` float DEFAULT NULL,
  `long` float DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

The type of single record to write is something like that:

|abdullah mun'im|abdullah_munim@test.com|0176028950|lot 4257, jln bunga raya 2, kg. sg. kelambu, 42700 banting|it would be awesome to drink water with bes-drink in this hec'drink'c event. don't scared of frozen yogurt, nobody will get hurt. ?  |male|2.7861321|101.5541346|1993-07-28|26|

This is the error occurred:

ERROR Database Writer 0:187:309:208:228 Execute failed: java.lang.Exception: Error while adding row #2 (Row0), reason: 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 'long) VALUES ('abdullah mun\'im', 'male', 26, '1993-07-28', 'abdullah_munim@test' at line 1

Can someone explain me what is wrong? Cause as it seems to me the syntax is correct with that version of MySQL server.

ADyson
  • 57,178
  • 14
  • 51
  • 63
UgoL
  • 839
  • 2
  • 13
  • 37
  • 1
    Possible duplicate of [When to use single quotes, double quotes, and back ticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql) – Madhur Bhaiya Dec 14 '18 at 14:05
  • 3
    "it seems to me the syntax is correct"..well clearly it mustn't be, otherwise you wouldn't be getting an error. Refusal to accept the facts doesn't make them any less true. But we can't help you fix it because you didn't show us either the query itself or the code which generates it. – ADyson Dec 14 '18 at 14:05
  • @ADyson Probably you misunderstood my words.. I didn't mean to refuse to admit that my procedure was wrong. Anyway my problem was caused by reserved keywords. – UgoL Dec 14 '18 at 14:30
  • @MadhurBhaiya I think that the answer you suggested does not represent my problem. Cause it was about reserved keywords. Not quotes or double quote or back ticks. – UgoL Dec 14 '18 at 14:34
  • @UgoL you use backticks around reserved keywords. It is even better to not use Reserved keywords for column/table names at all. – Madhur Bhaiya Dec 14 '18 at 14:42

1 Answers1

2

You have a column named long in your table and that is a reserved keyword in MySql, replace it with another name or enclose it with back ticks in your query.

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
  • Thank you! It was exactly my problem. I have fixed now by changing `long` to `lng` and everything works as expected. Is there a reserved keyword list page? Every time that I create a new empty table should I need to take a look at them for avoid this problem in the future? – UgoL Dec 14 '18 at 14:26
  • 1
    @UgoL, [Reserved keywords](https://dev.mysql.com/doc/refman/8.0/en/keywords.html) – Joakim Danielson Dec 14 '18 at 14:35