简体   繁体   English

如何使用 jdbctemplate 从多个表中批处理 select?

[英]How can I batch select from several tables with jdbctemplate?

I have the following query:我有以下查询:

select name_table.name, age_table.age, address_table.address
from 
name_table name_table,
age_table age_table,
address_table address_table
where 
name_table.id = age_table.id
 and age_table.id = address_table.id
 and name_table.new_date between ?(start_date) and ?(end_date)

How can i use JDBCTemplate to get the needed data in batches?如何使用JDBCTemplate批量获取需要的数据? The start_date and end_date are variables. start_date和end_date是变量。

First your query is not correct: from the syntax point of view "date" is a reserved word and from the logic point of view, you are doing a cross table join over the 3 tables because you don't have any condition to join them in the WHERE clause (and you should better do it using standard ANSI join).首先,您的查询不正确:从语法的角度来看,“日期”是一个保留字,从逻辑的角度来看,您正在对 3 个表进行交叉表连接,因为您没有任何条件来连接它们在 WHERE 子句中(最好使用标准 ANSI 连接)。 Second if your intent is to have the table names be parameters of the template, the answer is NO: table names and column names can't be parameters of a query.其次,如果您的意图是让表名成为模板的参数,答案是否定的:表名和列名不能成为查询的参数。 This has been answered several times on stackoverflow, including by AskTOM site's guys, explaining in details why: mainly the data structure of the result must be known at parse time.这已在 stackoverflow 上多次回答,包括 AskTOM 站点的人员,详细解释了原因:主要是结果的数据结构必须在解析时已知。

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

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