更新查询的SQL语法错误

时间:2014-08-06 16:01:52

标签: java mysql sql jdbc

我遇到了这个错误。

  

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:你有一个   SQL语法错误;查看与您的手册相对应的手册   MySQL服务器版本,用于在' like =' 1'附近使用正确的语法,   不喜欢=' 0',mealID =' 17'在哪里用餐ID =' 17''在第1行   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)   连接已关闭   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:408)     在com.mysql.jdbc.Util.handleNewInstance(Util.java:411)at   com.mysql.jdbc.Util.getInstance(Util.java:386)at   com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)at at   com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)at at   com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)at at   com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)at at   com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)at at   com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2809)at at   com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)     在   com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)     在OOADPJdb.database.DBController.updateRequest(DBController.java:73)     在projPackage.Menu.updateLike(Menu.java:409)at   projPackage.RetrieveMenuUI.likeBtnActionPerformed(RetrieveMenuUI.java:433)     在projPackage.RetrieveMenuUI.access $ 500(RetrieveMenuUI.java:21)at at   projPackage.RetrieveMenuUI $ 6.actionPerformed(RetrieveMenuUI.java:276)     在   javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)     在   javax.swing.AbstractButton中的$ Handler.actionPerformed(AbstractButton.java:2346)     在   javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)     在   javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)     在   javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)     在java.awt.Component.processMouseEvent(Component.java:6527)at   javax.swing.JComponent.processMouseEvent(JComponent.java:3321)at   java.awt.Component.processEvent(Component.java:6292)at   java.awt.Container.processEvent(Container.java:2234)at   java.awt.Component.dispatchEventImpl(Component.java:4883)at   java.awt.Container.dispatchEventImpl(Container.java:2292)at   java.awt.Component.dispatchEvent(Component.java:4705)at   java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)     在   java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)     在java.awt.Container.dispatchEventImpl(Container.java:2278)at   java.awt.Window.dispatchEventImpl(Window.java:2739)at   java.awt.Component.dispatchEvent(Component.java:4705)at   java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)at at   java.awt.EventQueue.access $ 400(EventQueue.java:97)at   java.awt.EventQueue $ 3.run(EventQueue.java:697)at   java.awt.EventQueue $ 3.run(EventQueue.java:691)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:75)     在   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:86)     在java.awt.EventQueue $ 4.run(EventQueue.java:719)at   java.awt.EventQueue $ 4.run(EventQueue.java:717)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:75)     在java.awt.EventQueue.dispatchEvent(EventQueue.java:716)at   java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)     在   java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)     在   java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)     在java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

这是我的SQL语句

  

dbQuery =" UPDATE菜单设置为='" + this.like +"',dislike ='" +   this.dislike +"',mealID ='" + this.mealID +"'&#34 ;;

     

dbQuery = dbQuery +"在哪里用餐ID ='" + this.mealID +"'";

确定这是对的,但它不起作用。

1 个答案:

答案 0 :(得分:8)

在我看来,问题是使用保留关键字LIKE作为列名,这总是一个坏主意。