1

I want to provide a values (...), (...), ... to a query. How can this be done with Spring's JDBCTemplate?

Example query:

with
bookings(date, start_time, end_time, room) as
(
    values ('2015-01-01'::date, '10:00'::time, '11:00'::time, 'office a'),
           ('2015-01-01'::date, '12:00'::time, '17:00'::time, 'office a'),
           ('2015-01-02'::date, '12:00'::time, '17:00'::time, 'meeting')
)
select * from bookings

I cannot find out how to bind the non-fixed list of values to one or multiple parameters dynamically. In the example, I have three rows, but I want to support any number of rows.

update

The related question does not really solve my question. I am not doing a batch update. I am providing a dynamic table via values (...), (...), ... to a CTE clause which I can use in the rest of the CTE query.

Franz They
  • 945
  • 9
  • 17
  • Possible duplicate of [Inserting multiple rows using JdbcTemplate](https://stackoverflow.com/questions/3165730/inserting-multiple-rows-using-jdbctemplate) – eis Nov 11 '17 at 11:35
  • @eis I added an edit to explain that this not solve my question. Thanks though! – Franz They Nov 11 '17 at 12:19
  • ah. retracted the close vote. That's probably not explicitly supported - you may need to just generate the SQL string dynamically and use jdbctemplate based on that. – eis Nov 11 '17 at 12:23
  • Ah, that sucks. You know any useful Java SQL libraries which I could use? I still want to use plain SQL (so no Hibernte/ORM), but I want to avoid creating SQL strings dynamically all over the place. – Franz They Nov 11 '17 at 12:29

0 Answers0