我在MySQL工作台中运行查询时出现JDBC错误但没有错误

时间:2012-01-21 13:54:57

标签: java mysql jdbc

我在MySQL数据库上运行查询,我正在使用JDBC,我使用MySQL工作台来运行查询。

当我在MySQL工作台上运行时,我得到了我期待的东西,但是当我在我的代码中运行它时,我得到了。

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第1行的“SELECT Character.CharacterID,Character.CharacterName,Characte”附近使用正确的语法

这是Java:

for (int i = 0; i < 3; i++) {
    try {
        result = s.executeQuery("USE `arbitrary-hero`; SELECT `Character`.CharacterID, `Character`.CharacterName, `Character`.CharacterLevel, SUM(ItemAttack), SUM(ItemHealth), SUM(ItemAgility), "
                + "SUM(ItemStrength), SUM(ItemSource) FROM `arbitrary-hero`.`Character` INNER JOIN `arbitrary-hero`.Character_Items ON `Character`.CharacterID = Character_Items.CharacterID INNER JOIN "
                + "Items ON Character_Items.ItemID = Items.ItemID WHERE Character_Items.Equiped = 1 and `Character`.CharacterName = "+ name[i] +" GROUP BY `Character`.CharacterName;;");
       }
       catch(Exception e) {
           System.out.println(e);
       }
    }
    s.close();

这是SQL:

SELECT `Character`.CharacterID, `Character`.CharacterName, `Character`.CharacterLevel, SUM(ItemAttack), SUM(ItemHealth), SUM(ItemAgility), SUM(ItemStrength), 
SUM(ItemSource) FROM `arbitrary-hero`.`Character` INNER JOIN `arbitrary-hero`.Character_Items ON
`Character`.CharacterID = Character_Items.CharacterID INNER JOIN Items ON 
Character_Items.ItemID= Items.ItemID WHERE Character_Items.Equiped = 1 and `Character`.CharacterName = "Maxinfet" GROUP BY `Character`.CharacterName;

1 个答案:

答案 0 :(得分:3)

不确定,但我认为你不能同时使用两个SQL命令,因此分号后的所有内容都是错误的。