JDBC错误,但在MySQL工作台中运行查询时没有错误 [英] JDBC error but no error when I run my query in MySQL workbench

查看:107
本文介绍了JDBC错误,但在MySQL工作台中运行查询时没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MySQL数据库上运行查询,正在使用JDBC,并且正在使用MySQL工作台运行查询.

I am running a query on a MySQL database, I am using JDBC and I am using MySQL workbench to run the query.

当我在MySQL工作台中运行它时,我得到了期望的结果,但是当我在代码中运行它时,我得到了期望的结果.

When I run it in MySQL work bench I get what I was expecting but when I run it in my code I get.

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

这是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;

推荐答案

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

Not sure, but I think you can't use two SQL commands together, so everything after the semi-colon is an error.

这篇关于JDBC错误,但在MySQL工作台中运行查询时没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆