Java 查询在MySQL提示符下执行,但不在应用程序中执行
以下查询在MySQL提示符中正确执行,但在Java中出错 您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,通过在第1行选择“A+”时选择平均案例等级,然后选择“A”时选择4,然后选择“A-”时选择4,然后选择3.7 w”,以获得正确的语法Java 查询在MySQL提示符下执行,但不在应用程序中执行,java,mysql,Java,Mysql,以下查询在MySQL提示符中正确执行,但在Java中出错 您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,通过在第1行选择“A+”时选择平均案例等级,然后选择“A”时选择4,然后选择“A-”时选择4,然后选择3.7 w”,以获得正确的语法 java.sql.ResultSet rslt= stmt.executeQuery("select name from student natural join takes t1 where (dept_name='Comp. Sci.')
java.sql.ResultSet rslt= stmt.executeQuery("select name from student natural join takes t1 where (dept_name='Comp. Sci.')" +
"group by ID" +
"order by (select avg( case grade " +
"when 'A+' then 4 " +
"when 'A' then 4 " +
"when 'A-' then 3.7 " +
"when 'B+' then 3.5 " +
"when 'B' then 3 " +
"when 'B-' then 2.7 " +
"when 'C+' then 2.5 " +
"when 'C' then 2 " +
"when 'C-' then 1 " +
"end) as avg_gpa " +
"from takes t2 " +
"where t1.ID=t2.ID) " +
"limit 10");
有人能帮忙吗?不要忘记每行后面的空格:
java.sql.ResultSet rslt= stmt.executeQuery(
"select name from student natural join takes t1 where (dept_name='Comp. Sci.') "+
"group by ID "+
"order by (select avg( case grade "+
"when 'A+' then 4 "+
"when 'A' then 4 "+
"when 'A-' then 3.7 "+
"when 'B+' then 3.5 "+
"when 'B' then 3 "+
"when 'B-' then 2.7 "+
"when 'C+' then 2.5 "+
"when 'C' then 2 "+
"when 'C-' then 1 "+
"end) as avg_gpa "+
"from takes t2 "+
"where t1.ID=t2.ID) "+
"limit 10");
在sql中,这是错误的:
"group by ID" +
"order by (select avg( case grade " +
这里有这样一个字符串:group by IDorder by select avg case grade
你看到问题了吗
在ID之后添加一个空格我认为这不是您的java代码。如何连接每行中的字符串?我省略了每行中的字符串,只是为了简化这里的代码,而不是java中的代码。。我不明白你说的不是我的java代码是什么意思?请也展示这一部分,我将向你展示问题……只是复制并粘贴了来自javano prob的语句:请随意点击我答案左上方的白色钩子接受。