您的位置:首页 > 数据库

解决使用sap数据库驱动查询hana数据库时,like '%param%' 失效问题

2017-11-07 18:32 1986 查看
开始使用mysql驱动访问数据库时我们正常的模糊查询写法是

concat('%',#{contractId,jdbcType=VARCHAR},'%')

但是hana语法中concat方法是只有两个参数的,因此会报出

### Cause: java.sql.SQLException: A problem occurred while trying to acquire a cached PreparedStatement in a background thread.
; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; A problem occurred while trying to acquire a cached PreparedStatement in a background thread.; nested exception is java.sql.SQLException: A problem occurred while trying to acquire a cached PreparedStatement in a background thread.] with root cause

com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [316]: wrong number of arguments in function invocation: line 8 col 28 (at pos 346)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.createException(SQLExceptionSapDB.java:334)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.generateDatabaseException(SQLExceptionSapDB.java:174)
at com.sap.db.jdbc.packet.ReplyPacket.buildExceptionChain(ReplyPacket.java:100)
at com.sap.db.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:1141)
at com.sap.db.jdbc.CallableStatementSapDB.sendCommand(CallableStatementSapDB.java:1964)
不知道的就会一直检查自己的程序,最后我也是查看了hana官方的文档后才清楚!!!

CONCAT

语法:

CONCAT (str1, str2)

描述:

返回位于 s

tr1 后

的 s

tr2 联

合组成的字符串。级联操作符(

||)与

该函数作用相同。 这是hana官方文档的原话!

所以我们调整下查询语句就可以解决了

LIKE concat('%',#{contId,jdbcType=VARCHAR}) || '%'

非常感谢项目组的老大哥给的文档,很好用!可以在博客一下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: