我在将数据保存到mysql工作台时出错



这是我的MYSQL数据库:在此处输入图像描述

在此处输入图像描述

这是代码在此处输入图像描述

在此处输入图像描述

和错误消息:运行:thg 12 032020 9:45:51 CH节目。StudentModify插入严重:无效com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误;查看与MySQL服务器版本对应的手册,了解在第1行的"Number"值("dsdsd","Male",23,"dsdsd',"232323")附近使用的正确语法位于java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)位于java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessor Impl.java:62)位于java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessor Impl.java:45)位于java.base/java.lang.reflect.CConstructor.newInstanceWithCaller(Constructor.java:500)位于java.base/java.lang.reflect.CConstructor.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(PreparedSStatement.java:1915)网址:com.mysql.jdbc.PreparedStatement.exexecute(PreparedSStatement.java:1254)在程序中。StudentModify.insert(StudentModifie.java:79)在程序中。StudentJFrame.btSaveActionPerformed(StudentJFFrame.java:260)在程序中。StudentJFrame$3.actionPerformed(StudentJFFrame.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.mouseRelease(BasicButton Listener.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(EventDispatch线程.java:203)位于java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatch线程.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)

也许你应该用一个词来写"电话号码",比如PhoneNumber。

或者在insert语句中的单词周围写上带反勾号的Phone Number——在create语句中,您在字段名称周围使用了反勾号。

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')' 

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

您的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();
}

也许你可以尝试而不是:

字符串url="jdbc:mysql://localhost:3306/studentmanagement?&useSSL=false";

尝试:

字符串url="jdbc:mysql://localhost:3306/studentmanagement?autoReconnet=true&useSSL=false";

最新更新