java - 有例外!您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以获取正确的语法
问题描述
我收到此错误我正在使用 java 和 javafx,它已连接到 MYsql DB 我在执行此语句从 java 到我的 sql 时收到此错误请帮助
有例外!
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 'update kstds.match SET kstds.match.Team1Goals=kstds.match.Team1Goals+1 where kst' at line 1
String Query ="use kstds; update kstds.match SET kstds.match.Team1Goals=kstds.match.Team1Goals+1 "
+ "where kstds.match.Team1ID= ( select kstds.team.TeamID from kstds.team where kstds.team.Name='AHLI' ) "
+ "and kstds.match.Matchid = 1 ; "
+ "Update kstds.match SET kstds.match.Team2Goals=kstds.match.Team2Goals+1 "
+ "where kstds.match.Team2ID= ( select kstds.team.TeamID from kstds.team where kstds.team.Name='AHLI' ) "
+ "and kstds.match.Matchid=1;";
解决方案
您正在尝试执行多个应该使用 addBatch
&完成的 sql 查询executeBatch
。
您不必执行use kstds
,因为与数据库的连接是通过 Java 设置的
尝试这个:
String Query1 ="update match SET match.Team1Goals=match.Team1Goals+1 "
+ "where match.Team1ID= ( select team.TeamID from team where team.Name='AHLI' ) "
+ "and match.Matchid = 1 ; "
String Query2 ="Update match SET match.Team2Goals=match.Team2Goals+1 "
+ "where match.Team2ID= ( select team.TeamID from team where team.Name='AHLI' ) "
+ "and match.Matchid=1;";
//stmt is your Statement and conn is your Connection
con.setAutoCommit(false);
stmt.addBatch(Query1);
stmt.addBatch(Query2);
stmt.executeBatch();
con.commit();
推荐阅读
- vue.js - VueJs - 表单提交时的 preventDefault()
- javascript - Adobe Campaign - 查询多个架构
- php - 用户注销时更新时间戳不起作用
- java - 使用 button.getTag() 会导致应用崩溃
- spring - 如何处理同时登录?
- python - 在便携式 python 上安装 pyreadline
- mongodb - 未找到 WiredTiger cpp 文件
- java - Spring Data JPA - 删除多对多条目
- angular - materialize 中的 formSelect() 方法在 Angular 6 输入中不起作用
- android - 更改 ic_launcher 资源文件在 Android Studio 中没有任何影响