Spring JdbcTemplate “insert into.. select from..” not working

a 夏天 提交于 2019-12-10 12:07:17

问题


I am trying to execute following SQL with Spring JdbcTemplate:

INSERT INTO japan_wht.PIVOT_20427002(doc_header_text, value_date, total_amt, is_refund)                    
 (SELECT 
    doc_header_text, DATE(value_date), SUM(LOCAL_CCY_AMT), is_refund
 FROM
    (SELECT 
        *
    FROM
        japan_wht.DATA_20427002
    WHERE IS_REFUND in ('N')
    ) t 
GROUP BY DATE(value_date) , doc_header_text, is_refund)

However, it does not insert anything into database table and no error is thrown.

When I tried to execute following SQL with JdbcTemplate, it works and inserts data in DB table:

INSERT INTO japan_wht.PIVOT_20427002(id, doc_header_text, value_date, total_amt, is_refund) values('1', '1', '2017-12-31', 3000, 'Y');

Below is my call to execute above SQLs:

jdbcTemplate.update(sqlString);

Not sure what is going wrong here.


回答1:


I had to resort to plain JDBC and it worked:

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/mySchema?autoReconnect=true&useSSL=false&rewriteBatchedStatements=true",
    "root", "root");
Statement stmt = conn.createStatement();
int flag = stmt.executeUpdate(sqlString);
LOGGER.info("Flag = {}", flag);

Not sure why Spring JdbcTemplate can not handle such thing!



来源:https://stackoverflow.com/questions/46194762/spring-jdbctemplate-insert-into-select-from-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!