The error may involve defaultParameterMap,The error occurred while setting parameters

created at 09-27-2021 views: 9

I encountered an error today, running RankDao.selectById(id) directly reported the error to me, I don’t understand

Error message

2021-09-22 10:40:58.824 ERROR 8364 --- [nio-8888-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: 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 'rank WHERE id=1' at line 1
### The error may exist in com/brilliantZC/music/dao/MusicRankDao.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=?
### Cause: java.sql.SQLSyntaxErrorException: 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 'rank WHERE id=1' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 'rank WHERE id=1' at line 1] with root cause

solution

At the beginning, various methods of google were used, and it was said

  1. The value of the column in the created table is less than the actual value and an error is reported
  2. Forgot to write @Resource or @Autowired annotations on the Service interface introduced by the Controllor layer
  3. The method called by the Controllor layer is private, causing the distribution to fail
  4. Check whether the Mapper interface code complies with the specification (Mybatis-plus used is automatically ignored)

Tried it all but it still didn’t work, so I executed it with the wrong sql statement

SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=1

Still reporting an error

music> SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=1
[2021-09-22 10:55:58] [42000][1064] 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 'rank WHERE id=1' at line 1

Then I was at a loss, and then I removed the query statement and still reported an error

SELECT id,song_list_id,consumer_id,score FROM rank

Then continue to Google, I saw that because rank is a keyword, it cannot be used directly as a non-keyword, and it needs to be used by adding `` sign. Executable after replacement

SELECT id,song_list_id,consumer_id,score FROM `rank`

Then I changed the table name and the error was resolved! ! !

created at:09-27-2021
edited at: 09-27-2021: