gpt4 book ai didi

Java 和 MSSQL 从数据库获取数据时出现问题

转载 作者:行者123 更新时间:2023-11-29 07:45:44 25 4
gpt4 key购买 nike

好吧,我有点困惑 atm,我正在尝试使用 java 和 mssql 从数据库中检索一些数据。

在sql中我这样写:

use MyChamp SELECT * 
FROM [GROUP]
JOIN Team on [Group].GroupID = Team.GroupID
JOIN Match on Team.TeamID = HomeTeamID
WHERE [GROUP].GroupID = 9

并且它有效。

在 java 中,我要执行的字符串如下所示:

String sql = "SELECT * FROM [GROUP]"
+ "JOIN Team on [Group].GroupID = Team.GroupID"
+ "JOIN Match on Team.TeamID = HomeTeamID"
+ "WHERE [GROUP].GroupID = 9"
+ "ORDER BY MatchRound:";

它不起作用,我收到 sql 错误消息说:

Error: S0001Incorrect syntax near 'Match'.

但我找不到错误:(

最佳答案

在字符串终止引号后添加空格“

String sql = "SELECT * FROM [GROUP] "
+ "JOIN Team on [Group].GroupID = Team.GroupID "
+ "JOIN Match on Team.TeamID = HomeTeamID "
+ "WHERE [GROUP].GroupID = 9 "
+ "ORDER BY MatchRound "

如果你不这样做,你的字符串将像这样生成。

SELECT * FROM [GROUP]JOIN Team on [Group].GroupID = Team.GroupIDJOIN Match on Team.TeamID = HomeTeamIDWHERE [GROUP].GroupID = 9ORDER BY MatchRound

关于Java 和 MSSQL 从数据库获取数据时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27857105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com