将动态值传递给wso2 dblook'like'查询

brtdzjyr  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(373)

场景:我使用dblookup mediator通过传递部分名称来检索全名。为此,我在sql中使用了like选项。
全名:约翰·史密斯
传递值:john
sql:从fullname(如“%john%”)所在的表中选择*
已用配置:

<dblookup>
   <connection>
      <pool>
         <driver>com.mysql.jdbc.Driver</driver>
         <url>jdbc:mysql://localhost:3306/world</url>
         <user>root</user>
         <password>root</password>
      </pool>
   </connection>
   <statement>
      <sql>SELECT TP_ID, TP_FULL_NAME, TP_USER_NAME, TP_USER_PASSWORD, TP_ACTIVE, TP_CHANGED_TIME, TP_TENANT_ID FROM tp_user WHERE TP_FULL_NAME like ('%?%');</sql>
      <parameter expression="get-property('name')" type="VARCHAR" />
   </statement>
</dblookup>

错误:

[2018-11-08 13:04:14,943] [] ERROR - DBLookupMediator SQL Exception occurred while executing statement : SELECT TP_ID, TP_FULL_NAME, TP_USER_NAME, TP_USER_PASSWORD, TP_ACTIVE, TP_CHANGED_TIME, TP_TENANT_ID FROM tp_user WHERE TP_FULL_NAME like ('%?%'); against DataSource : jdbc:mysql://localhost:3306/world
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
daupos2t

daupos2t1#

修改sql语句如下;
选择tp_id、tp_full_name、tp_user_name、tp_user_password、tp_active、tp_changed_time、tp_tenant_id from tp_user where tp_full_name like concat('%,?,'%');
如需进一步参考,请点击此链接

相关问题