Cannot use a Like query in a JSP prepared statement?

Posted by SeerUK on Stack Overflow See other posts from Stack Overflow or by SeerUK
Published on 2010-05-18T12:24:10Z Indexed on 2010/05/18 12:30 UTC
Read the original article Hit count: 209

Filed under:
|
|
|
|

OK, first the query code and query:

ps = conn.prepareStatement("select instance_id, ? from eam_measurement where resource_id in (select RESOURCE_ID from eam_res_grp_res_map where resource_group_id = ?) and DSN like '?' order by 2");
ps.setString(1,"SUBSTR(DSN,27,16)");
ps.setInt(2,defaultWasGroup);
ps.setString(3,"%Module=jvmRuntimeModule:freeMemory%");
rs = ps.executeQuery();
while (rs.next()) { bla blah blah blah ...

Returns an empty resultSet.

Through basic debugging I have found its the 3rd bind that is the problem i.e. DSN like '?'

I have tried all kinds of variations, the most sensible of which seemed to be using:

DSN like concat('%',?,'%')

bit that doesn' work as I am missing the ' ' either side of the concatenated string so I try

DSN like ' concat('%',Module=P_STAG_JDBC01:poolSize,'%') ' order by 2

but I just can't seem to find a way to get them in that works.

What am I missing? :) Thanks!

© Stack Overflow or respective owner

Related posts about jsp

Related posts about Oracle