MySQL in Java: using a LIKE query on a varbinary field?

1k views Asked by At

Basically, I have a table with an indexed varbinary field in it.

I want to say: return all rows whose varbinary field starts with (an array of bytes).

How do I do this in Java? I have a PreparedStatement with "SELECT * WHERE data LIKE ?" but if I set the binary array as an argument with setBytes, how do I specify that the LIKE query should be a prefix (as opposed to another type of regular expression)?

1

There are 1 answers

0
Jim Garrison On

Although not explicitly stated in the manual, it is implied in several places that LIKE works on varbinary, with the usual wildcard characters. The binary array you pass to setBytes should contain the '%' at the appropriate place.

You'll just have to try it and see what happens.