简体   繁体   English

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

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

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? 如何在Java中执行此操作? I have a PreparedStatement with "SELECT * WHERE data LIKE ?" 我有一个PreparedStatement,上面有“ 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)? 但是如果我将二进制数组设置为带有setBytes的参数,如何指定LIKE查询应为前缀(与另一种正则表达式相对)?

Although not explicitly stated in the manual, it is implied in several places that LIKE works on varbinary, with the usual wildcard characters. 尽管在手册中没有明确说明,但在很多地方都暗示LIKE在varbinary上工作,并具有通常的通配符。 The binary array you pass to setBytes should contain the '%' at the appropriate place. 传递给setBytes的二进制数组应在适当位置包含'%'。

You'll just have to try it and see what happens. 您只需要尝试一下,看看会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM