好的,我有点困惑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'.
但我找不到错误:(
答案 0 :(得分:2)
在字符串终止引用后放置空格“
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