Java中的MySQL:在varbinary字段上使用LIKE查询?

时间:2022-06-08 00:09:44

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

基本上,我有一个带有索引varbinary字段的表。

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

我想说:返回varbinary字段以(字节数组)开头的所有行。

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)?

我如何用Java做到这一点?我有一个带有“SELECT * WHERE数据LIKE?”的PreparedStatement。但是如果我将二进制数组设置为带有setBytes的参数,我如何指定LIKE查询应该是前缀(而不是另一种类型的正则表达式)?

1 个解决方案

#1


0  

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.

虽然手册中没有明确说明,但是在一些地方暗示LIKE在varbinary上工作,使用通常的通配符。传递给setBytes的二进制数组应该在适当的位置包含'%'。

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

你只需要尝试一下,看看会发生什么。

#1


0  

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.

虽然手册中没有明确说明,但是在一些地方暗示LIKE在varbinary上工作,使用通常的通配符。传递给setBytes的二进制数组应该在适当的位置包含'%'。

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

你只需要尝试一下,看看会发生什么。