5

Hi I am using Spring Boot 1.3.5.RELEASE. I have a situation where I need to fire

INSERT INTO someTable1 (col1, col2, col3) 
SELECT (10346, someTable2Id, 1048) FROM someTable2. 

I am using Spring JdbcTemplate.

String sql = "INSERT INTO someTable1( col1, col2, col3 ) 
                   SELECT 10346, someTable2Id, 1048 
                     FROM someTable2";
             jdbcTemplate.update(sql);

While executing this statement, it got stuck on jdbcTemplate.update(sql) line. It seems JdbcTemplate is not responding well to INSERT INTO...SELECT Statement. Same query is working fine from Database Editors.

Prabhat Sinha
  • 1,500
  • 20
  • 32
Sarvesh
  • 551
  • 1
  • 10
  • 25
  • Is it possible that `someTable2` can have too much records ? Can you try the same for only 1 record from `someTable2` by adding a `WHERE` statement. Can you provide the type of `jdbcTemplate` are you using `NamedParameterJdbcTemplate` ? And lastly are other calls from the BE to the DB working ? – Lazar Lazarov Nov 09 '16 at 14:20
  • @lazarov, I tried the same query with sql developer. It is working there. I tried both `JdbcTemplate` and `NamedParameterJdbcTemplate`. It is giving me no error. But when I call `jdbcTemplate.update(sql)`, execution hangs there. Then I tried with normal `JDBC` program, still no error but execution hangs there. `someTable2` has nearly 700 records. – Sarvesh Nov 12 '16 at 15:09
  • Did you get answer to this? If yes, can you please post here and help others? thanks :) – Akshay Lokur Sep 13 '17 at 07:32
  • @AkshayLokur, I did not get any solution for this. I completely excluded `INSERT INTO...SELECT` from my application. – Sarvesh Sep 14 '17 at 08:58
  • Use `jdbctemplate.execute()` – Thirumal Jul 18 '20 at 07:30

0 Answers0