Home > Mobile >  How can I batch select from several tables with jdbctemplate?
How can I batch select from several tables with jdbctemplate?

Time:09-29

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? The start_date and end_date are variables.

CodePudding user response:

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). 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.

  • Related