场景:我已经使用DBLookup中介器通过传递部分名称来检索全名。为此,我在sql中使用了like选项。
全名:John Smith
传递的值:John
SQL:SELECT*FROM表,其中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)
如下更改sql语句;
从TP_USER中选择TP_ID、TP_FULL_NAME、TP_USER_NAME、TP_USER_PASSWORD、TP_ACTIVE、TP_CHANGED_TIME、TP_TENANT_ID,其中TP_FULL_NAME类似CONCAT('%',?,'%'(;
如需进一步参考,您可以点击此链接