简体   繁体   English

批处理模式下的 Select JDBC SQL

[英]Select in batch mode JDBC SQL

Why is there no batchSelect in JDBC?为什么JDBC中没有batchSelect?

Is there some good way to handle select for multiple keys or ids?是否有一些好方法来处理多个键或 ID 的 select?

Creating a query matching the length of all possible keys seem silly, because the database couldn't reuse prepared statements.创建与所有可能键的长度匹配的查询似乎很愚蠢,因为数据库无法重用准备好的语句。 Using stored procedures is very database dependant.使用存储过程非常依赖数据库。

Are their any better ways?他们有更好的方法吗?

Use the IN clause.使用IN子句。 Eg例如

SELECT 
    id, name, value 
FROM 
    entity
WHERE 
    id IN (1, 13, 42)

This returns the entities having an id of 1 , 13 and 42 in a ResultSet with 3 rows.这将返回具有 3 行的ResultSetid11342的实体。

Using the IN clause in a JDBC PreparedStatement is however not exactly trivial.然而,在 JDBC PreparedStatement中使用IN子句并非易事。 As to how to do this, check this question: What is the best approach using JDBC for parameterizing an IN clause?至于如何做到这一点,请检查以下问题: 使用 JDBC 参数化 IN 子句的最佳方法是什么?

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

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