我在一个函数中执行以下查询,但出现“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+" ;");