1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

£神魔★判官ぃ 2023-07-03 07:08 100阅读 0赞

今天在测试管理员用户登录的过程中遇到的这个错误,特别的郁闷,感觉自己写的sql语句没有问题啊!但是就是报错……

直接看图:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyNjgwMzI3_size_16_color_FFFFFF_t_70

  1. 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 'admin where adminId = '111111' and password = '111111'' at line 1
  2. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
  3. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
  4. at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
  5. at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:955)
  6. at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1005)
  7. at com.book.dao.AdminDao.adminLogin(AdminDao.java:18)
  8. at com.bookface.LogOnFram.logCheck(LogOnFram.java:191)
  9. at com.bookface.LogOnFram$1.actionPerformed(LogOnFram.java:117)
  10. at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
  11. at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
  12. at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
  13. at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
  14. at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
  15. at java.awt.Component.processMouseEvent(Unknown Source)
  16. at javax.swing.JComponent.processMouseEvent(Unknown Source)
  17. at java.awt.Component.processEvent(Unknown Source)
  18. at java.awt.Container.processEvent(Unknown Source)
  19. at java.awt.Component.dispatchEventImpl(Unknown Source)
  20. at java.awt.Container.dispatchEventImpl(Unknown Source)
  21. at java.awt.Component.dispatchEvent(Unknown Source)
  22. at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
  23. at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
  24. at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
  25. at java.awt.Container.dispatchEventImpl(Unknown Source)
  26. at java.awt.Window.dispatchEventImpl(Unknown Source)
  27. at java.awt.Component.dispatchEvent(Unknown Source)
  28. at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  29. at java.awt.EventQueue.access$500(Unknown Source)
  30. at java.awt.EventQueue$3.run(Unknown Source)
  31. at java.awt.EventQueue$3.run(Unknown Source)
  32. at java.security.AccessController.doPrivileged(Native Method)
  33. at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
  34. at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
  35. at java.awt.EventQueue$4.run(Unknown Source)
  36. at java.awt.EventQueue$4.run(Unknown Source)
  37. at java.security.AccessController.doPrivileged(Native Method)
  38. at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
  39. at java.awt.EventQueue.dispatchEvent(Unknown Source)
  40. at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  41. at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  42. at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  43. at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  44. at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  45. at java.awt.EventDispatchThread.run(Unknown Source)

查阅了一番,终于找到了原因:出现在表名或字段名设计的过程中出现了mysql关键字导致的

遇到这种情况,我们可以直接在mysql中运行sql语句,看看能否通过:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyNjgwMzI3_size_16_color_FFFFFF_t_70 1

因此在设计表名或字段名的时候,应尽量避免和sql中的关键字发生冲突

发表评论

表情:
评论列表 (有 0 条评论,100人围观)

还没有评论,来说两句吧...

相关阅读