1. 程式人生 > 實用技巧 >sql錯誤記錄

sql錯誤記錄

1、錯誤:

 Servlet.service() for servlet [dispatcherServlet] in context with path [/system] 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 '"test"' at line 1 ### The error may exist in file [D:\dev_project\course\system\target\classes\mapper\TestMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT id,name FROM "test"

原因是sql語句有語法問題。

select
“id”,“name” from "user" 其中id和name是user表的欄位,問題在三個都不能加雙引號,user表名加雙引號後報上述錯誤,而欄位名加雙引號會被識別為字串,從而在表中找到相應的字串而不是欄位對應的內容。
故正確寫法如下:
select id,name from user