我在一个函数中执行下面的查询,但得到“SQLGrammarException:无法执行本机批量操作查询错误”异常。
任何人都可以告诉我它的解决方案吗?我不想使用HQL。
query = session.createSQLQuery("CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"' and datestamp < '"+endDate+"' and `"+groupBy+"` = '"+groupByBar1+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+" ;CREATE TEMPORARY TABLE test select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"' and datestamp < '"+endDate+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+" ;alter table test add column `"+groupByBar1+"` INTEGER ;");
query.executeUpdate();
query = session.createSQLQuery("update test,temp set `"+groupByBar1+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"` ; drop table temp ; CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"' and datestamp < '"+endDate+"' and `"+groupBy+"` = '"+groupByBar2+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+" ;alter table test add column `"+groupByBar2+"` INTEGER ; ");
query.executeUpdate();
query = session.createSQLQuery("update test,temp set `"+groupByBar2+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"` ; drop table temp ; CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"' and datestamp < '"+endDate+"' and `"+groupBy+"` = '"+groupByBar3+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+" ;alter table test add column `"+groupByBar3+"` INTEGER ;");
query.executeUpdate();
query = session.createSQLQuery("update test,temp set `"+groupByBar3+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"` ; drop table temp ; CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"' and datestamp < '"+endDate+"' and `"+groupBy+"` = '"+groupByBar4+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+" ;alter table test add column `"+groupByBar4+"` INTEGER ;");
query.executeUpdate();
query = session.createSQLQuery("update test,temp set `"+groupByBar4+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"` ; drop table temp ; CREATE TEMPORARY TABLE temp select `"+xAxis+"`, sum(value) as length from (select * from "+xAxis+"Table union select `"+xAxis+"`, sum(cycles) as value from "+Constants.TABLE_NAME+" where datestamp >= '"+startDate+"' and datestamp < '"+endDate+"' and `"+groupBy+"` = `"+Constants.OTHERS+"' and `"+xAxis+"` = 'Uptime' group by `"+xAxis+"`) as t group by `"+xAxis+"` "+fixOrderString+" ;alter table test add column `"+Constants.OTHERS+"' INTEGER ;");
query.executeUpdate();
query = session.createSQLQuery("update test,temp set `"+Constants.OTHERS+"` = temp.length where test.`"+xAxis+"` = temp.`"+xAxis+"`;");
query.executeUpdate();
query = session.createSQLQuery("select * from test "+fixOrderString+" ;");
答案 0 :(得分:0)
您希望捕获该异常并将其打印出来以查看根本原因。 例如。你可以用Log4j做到这一点:
log.error("Error", e);
根本原因可能是由于某种原因,在第一个语句中创建的临时表实际上未在以下语句中看到。