在程序中运行sql报错, 
ERROR 1067 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TEMPORARY TABLE tmp_table 
SELECT acc.accId, acc.accName, '2010-06-10' as tmpDate FROM ' sql语句如下: 
DROP TABLE IF EXISTS tmp_table; 
CREATE TEMPORARY TABLE tmp_table 
SELECT acc.accId, acc.accName, '2010-06-10' as tmpDate FROM tbl_account acc; 
insert into tmp_table SELECT acc.accId, acc.accName, '2010-06-11' as tmpDate FROM tbl_account acc; 
insert into tmp_table SELECT acc.accId, acc.accName, '2010-06-12' as tmpDate FROM tbl_account acc; 
select tmp.accName,att.seqId,att.attendanceType,att.beginDateTime,att.comment 
from tmp_table tmp left join tbl_attendance att 
on tmp.accId = att.accId  
and tmp.tmpDate = str_to_date(att.beginDateTime, '%Y-%m-%d') 
and str_to_date(att.beginDateTime, '%Y-%m-%d') >= '2010-06-10' 
and str_to_date(att.beginDateTime, '%Y-%m-%d') <= '2010-06-12' 
where 1=1; 
DROP TABLE tmp_table; 这段sql在MySQL中运行没问题,但是放到程序中运行就报异常,目前程序是基于struts2 + spring + hibernate,请大家指点一下,谢谢 

解决方案 »

  1.   

    呵呵  支持下1楼的兄弟。 它分析的不错。 要学会看异常 You have an error in your SQL syntax 这个表示你的语法有问题。如果你确信你的语法没问题 那就关注下符号。
      

  2.   

    我这段SQL放到MySQL中运行是没问题的,但是在程序中运行就出异常,再说";"我也加了,
    this.getSession().createSQLQuery(hql.toString()).list()
    hql就是这段SQL语句。