[英]How can I batch select from several tables with jdbctemplate?
我有以下查詢:
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)
如何使用JDBCTemplate批量獲取需要的數據? start_date和end_date是變量。
首先,您的查詢不正確:從語法的角度來看,“日期”是一個保留字,從邏輯的角度來看,您正在對 3 個表進行交叉表連接,因為您沒有任何條件來連接它們在 WHERE 子句中(最好使用標准 ANSI 連接)。 其次,如果您的意圖是讓表名成為模板的參數,答案是否定的:表名和列名不能成為查詢的參數。 這已在 stackoverflow 上多次回答,包括 AskTOM 站點的人員,詳細解釋了原因:主要是結果的數據結構必須在解析時已知。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.