这是我的代码:
Assume metaname = "hello world";
String metaname = metaname.replaceAll("/", "\\/").replaceAll(" ", "\\ ");
adding metaname as parameter to query.
FreeformQuery query = new FreeformQuery("select * from table where metaname =" +metaname);
这给了我错误:
com.microsoft.sqlserver.jdbc.SQLServerException:'world'附近的语法不正确。
答案 0 :(得分:0)
尝试2个反斜杠" \\"作为反斜杠,它的自我需要被逃脱
答案 1 :(得分:0)
通过将metaname放在单引号中来解决此问题: FreeformQuery query = new FreeformQuery(" select * from table,其中metaname ='" + metaname +"'");