select * from ( select Id id ,L_title tit,L_con con,L_date date,L_author aut from lab
union select Id id ,I_title tit,I_con con,I_date date,I_author aut from introduction
union select Id id ,M_title tit,M_con con,M_date date,M_author aut from mien
union select Id id ,R_title tit,R_con con,R_date date,R_author aut from research
union select Id id ,Title tit,Content con,Date date,Author aut from news
union select Id id ,W_title tit,W_con con,W_date date,W_author aut from windows) a where a.tit='作者' or a.con='作者' or a.aut='作者' order by date desc 这个语句在MYSQL中可以查询, 但是放到java中 就不行了, 最多最能写两句,如下:
select * from ( select Id id ,L_title tit,L_con con,L_date date,L_author aut from lab
union select Id id ,I_title tit,I_con con,I_date date,I_author aut from introduction
) a where a.tit='作者' or a.con='作者' or a.aut='作者' order by date desc
否则将报错:
[ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO net.fckeditor.connector.Dispatcher - Connector initialized to net.fckeditor.connector.impl.ContextConnector
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'select Id id ,M_title tit,M_con con,M_date date,M_author aut from mien union sel' at line 1
union select Id id ,I_title tit,I_con con,I_date date,I_author aut from introduction
union select Id id ,M_title tit,M_con con,M_date date,M_author aut from mien
union select Id id ,R_title tit,R_con con,R_date date,R_author aut from research
union select Id id ,Title tit,Content con,Date date,Author aut from news
union select Id id ,W_title tit,W_con con,W_date date,W_author aut from windows) a where a.tit='作者' or a.con='作者' or a.aut='作者' order by date desc 这个语句在MYSQL中可以查询, 但是放到java中 就不行了, 最多最能写两句,如下:
select * from ( select Id id ,L_title tit,L_con con,L_date date,L_author aut from lab
union select Id id ,I_title tit,I_con con,I_date date,I_author aut from introduction
) a where a.tit='作者' or a.con='作者' or a.aut='作者' order by date desc
否则将报错:
[ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO net.fckeditor.connector.Dispatcher - Connector initialized to net.fckeditor.connector.impl.ContextConnector
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'select Id id ,M_title tit,M_con con,M_date date,M_author aut from mien union sel' at line 1
怀疑你在java拼接字符串的时候哪里出错了,把java执行的sql打印出来看看吧。
另外,如果你的这些表里没有重复记录,用union all吧,效率更高。
错误提示在第三个union附近,你删了后面的肯定可能就是把错误部分删掉了