Recently get a project, there is a demand that requires PC to read information and write to the database.
Among them, you have encountered 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 '1)' at line 1
Java middle key value is used ('
) single quotes, column name (`) back single quotes. That is, the above row of digital keys is the left side ~ symbol, switching the English input method is the back single quotation mark.
such as
int result = ed.insertData("insert into information(`nowtime`,`data`) values(current_time,'A');");
insertData
is responsible for performing this SQL statement, and he finally returns the number of affected bars, this is not used.
The column names are nowtime
and data
, respectively, and the value writes to the database is current_time
and character A
(here single quotes).
Solution: Modify the name of the table, such as your column name can't be called Update and other keywords
This is generally seen
However, after checking for half day, my statement has no problem! ! ! ! !
Later discovered a problem.
Such as this error
int result = ed.insertData("insert "+"into testtest"
+ "values(1) ");
And there is no problem with the code synthesize a sentence.
int result = ed.insertData("insert into testtest values(1) ");
I didn't understand the life, and I suddenly realized it after the comment area.
There is no space between the first TestTest and the back VALUES! ! ! ! So of course I will report an error.
So you should pay attention to you or forget the space, this error often occurs when you go back,
So short SQL statement is still written in a sentence, reducing BUG generation efficiency Haha
Bug is deep like the ocean, one for a whole day.