【问题标题】:i have a error when save data in to mysql work bench [closed]将数据保存到mysql工作台时出现错误[关闭]
【发布时间】:2021-03-15 14:39:11
【问题描述】:

这是我的MYSQL数据库:enter image description here

enter image description here

这是代码 enter image description here

enter image description here

和错误消息: 跑步: thg 12 03, 2020 9:45:51 CH program.StudentModify 插入 严重:无 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'Number) values('sdsdsd','Male',23,'sdsdsd','232323')' 附近使用正确的语法 在 java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) 在 java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) 在 com.mysql.jdbc.Util.handleNewInstance(Util.java:403) 在 com.mysql.jdbc.Util.getInstance(Util.java:386) 在 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944) 在 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933) 在 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869) 在 com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524) 在 com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675) 在 com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465) 在 com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1915) 在 com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1254) 在 program.StudentModify.insert(StudentModify.java:79) 在 program.StudentJFrame.btSaveActionPerformed(StudentJFrame.java:260) 在 program.StudentJFrame$3.actionPerformed(StudentJFrame.java:111) 在 java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) 在 java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) 在 java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) 在 java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) 在 java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279) 在 java.desktop/java.awt.Component.processMouseEvent(Component.java:6636) 在 java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342) 在 java.desktop/java.awt.Component.processEvent(Component.java:6401) 在 java.desktop/java.awt.Container.processEvent(Container.java:2263) 在 java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012) 在 java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321) 在 java.desktop/java.awt.Component.dispatchEvent(Component.java:4844) 在 java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919) 在 java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548) 在 java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489) 在 java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307) 在 java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2764) 在 java.desktop/java.awt.Component.dispatchEvent(Component.java:4844) 在 java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772) 在 java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721) 在 java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715) 在 java.base/java.security.AccessController.doPrivileged(AccessController.java:391) 在 java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) 在 java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95) 在 java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745) 在 java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743) 在 java.base/java.security.AccessController.doPrivileged(AccessController.java:391) 在 java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) 在 java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) 在 java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) 在 java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) 在 java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) 在 java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) 在 java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 在 java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

【问题讨论】:

    标签: java mysql mysql-workbench


    【解决方案1】:

    也许你应该把“电话号码”写成一个单词,比如 PhoneNumber。

    或者写Phone Number,并在插入语句中的单词周围加上反引号 - 在创建语句中,您在字段名称周围使用反引号。

    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 'Number) 
    values('sdsdsd','Male',23,'sdsdsd','232323')' 
    

    '号码可能是'电话号码'的第二部分。

    【讨论】:

      【解决方案2】:

      您的 SQL 查询中有电话号码。

      在您的代码中,您每次使用该方法时都会打开和关闭连接 您可以移动连接和关闭单独的方法

      例如:

          public Connection connect() throws SQLException {
              Connection connection = null;
                  DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
              connection = DriverManager.getConnection(URL,USER,PASSWORD);
      
              return connection;
          }
      
        public void disconnect(Connection connection) throws SQLException {
              connection.close();
          }
      

      【讨论】:

        【解决方案3】:

        也许你可以试试:

        String url = "jdbc:mysql://localhost:3306/studentmanagement?&useSSL=false"

        试试:

        String url = "jdbc:mysql://localhost:3306/studentmanagement?autoReconnet=true&useSSL=false"

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-07-17
          • 1970-01-01
          相关资源
          最近更新 更多