【发布时间】:2020-04-14 23:17:52
【问题描述】:
代码截图
首先这是我在这里的第一篇文章,我对编程很陌生,所以很抱歉,如果我问我的帖子的愚蠢问题,我会丢失一些信息。请告诉我。
我在尝试更改 SQL 数据库中的字段时收到上述失败消息。我检查了其他几个有类似问题的帖子,但它们都有不同的原因,在我看来我的问题还有另一个问题。 随附的屏幕截图显示了一种有效的方法和一种导致问题的方法。对于我的生活,我无法弄清楚问题是什么。
完整的失败信息是:
Fehlermeldung: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'taskID =79' at line 1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'taskID =79' at line 1
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1912)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1251)
at databaseConnection.TaskDAOimplDB.updateTask(TaskDAOimplDB.java:110)
at procedure.Procedure.main(Procedure.java:36)
]
【问题讨论】:
-
在 updateTask 语句中的“UPDATE Tasks SET DueDate =”末尾和“WHERE taskID =”开头添加一个空格。
-
也不要使用字符串连接构建 SQL 查询。
-
您是否尝试过将 TaskDAOimplDB.java 的第 110 行更改为 pstmt.executeUpdate()?
-
感谢您的快速回复。我进入了步伐。现在失败消息更改为“字段列表中的未知列 'March2999'”(其中 March2999 是我作为参数传递的值)。更改为 executeUpdate() 对我所看到的没有任何影响。
-
请勿发布包含代码的图片,复制您的代码并粘贴您的问题。请在您提出下一个问题之前阅读此内容 -> meta.stackoverflow.com/questions/303812/…