我从事的是hibernate。
下面的代码曾在MSSQL很好,但在MySQL允许误差用于在MySQL和SQL Server中连接字符串的SQL语句
代码:
Criteria criteria = session.createCriteria(table1.class);
criteria.add(Restrictions.sqlRestriction("(select this11_.um_email as y0_ from table2 this11_ where this11_.id='"+IDvalue+"') like '%'+this_.post_id+'%'"));
堆栈跟踪:
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 '+this_.post_id+'%'' at line 1
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
任何人可以帮我解决了这个?
ya它工作正常的MySQL,但它不会为mssql.My应用程序与mssql和mysql连接。 – 2014-10-06 14:00:37
@sejal'CONCAT()'是SQL标准的一部分,也适用于mssql。该解决方案适用于mysql和mssql。 – Bohemian 2014-10-06 14:14:42
当我尝试在mssql中执行此查询时,它会给出错误,如“消息195,级别15,状态10,行2 'CONCAT'不是一个公认的内置函数名称。” – 2014-10-06 14:16:24