prepareStatement doesn't Like it when i use: LIKE %XYZ%'

Hey,

I want to execute this:

st = conn.prepareStatement("select msgid from log.msg_info where subject like ? ");

st.setString(1, "'%" + (String)names.get(i) + "%' ");

ResultSet rs = st.executeQuery();

while (rs.next()){//for each mail with that timestamp

......

}

rs.close();

-

The problem is that whenever i execute the query i get an empty result set

but, if i got to the database and execute the query manually i get the result i needed.

here is an example of the query:

"select msgid from log.msg_info where subject like '%57.52.0923%' "

i tried using escape chars but that didn't do the trick either.

can anyone help ?

[730 byte] By [BamBam_a] at [2007-11-27 9:05:48]
# 1
try this instead:st.setString(1, "%" + names.get(i) + "%");
java_2006a at 2007-7-12 21:40:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

The single apostroph ' is only needed in a db query tool (otherwise it wouldn't possibke to ask for empty sign ' ').

If you fill the value in a prepared statement the whole string you deliver as parameter is taken, if you bracket your string with the ' it will be part of string to search for

Sucharda at 2007-7-12 21:40:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
java_2006 &Suchard thank u both :) i split the start between u 2 (if they mean anything to u ) to be fair .
BamBam_a at 2007-7-12 21:40:29 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...