Java - 准备好的语句和数组
如何在准备好的语句中处理数组?即,我想做一个查询,我得到的参数之一是我想在查询中使用的字符串数组(不要选择数组中具有字段的行)?
How can I handle an array in a prepared statement? i.e, I want to do a query and one of the parameters I get is an array of strings which I want to use in the query (Don't select rows that have a field that's in the array)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
某些 JDBC 驱动程序可能已经(在 JDBC 4 之前)包含支持预准备语句中数组类型参数的专有扩展 - 您需要为此咨询 API。这意味着您必须在 SQL 中使用和操作类似数组的类型。
一种解决方法是使用临时表。这些是此类解决方案的元步骤:
方法 - EJB 或 Spring);
示例:IN 表达式被 JOIN 替换为临时表。
Some JDBC drivers may already (before JDBC 4) contain proprietary extensions that support array-type parameters in prepared statements - you would need to consult with API for this. This would mean that you have to use and manipulate array-like type in SQL.
One work around would be using temporary tables. These are meta-steps for such solution:
method - EJB or Spring);
Example: IN expression gets replaced with JOIN to temporary table.
现在这可能对您没有帮助,但我读到 JDBC 4 将支持 2003 版 SQL 中定义的数组类型。
This probably won't help you now, but I read that JDBC 4 will support array types as defined in the 2003 version of SQL.
这很大程度上取决于所使用的 RDBMS。通常,此类功能可以使用供应商的 jdbc 驱动程序扩展来完成。
我发现的 2 个变体是(针对 Oracle):
http://blogs.itemis.de /kloss/2009/03/05/arrays-preparedstatements-jdbc-and-oracle/
http://www.angelfire.com/home/jasonvogel/java_jdbc_arrays.html
尝试看看这是否对您有帮助。
That pretty much depends upon RDBMS being used. Often such functionality can be accomplished using vendor's jdbc driver extensions.
2 variants I found are (for Oracle):
http://blogs.itemis.de/kloss/2009/03/05/arrays-preparedstatements-jdbc-and-oracle/
http://www.angelfire.com/home/jasonvogel/java_jdbc_arrays.html
Try to look if that would help you.