Spring JdbcTemplate“插入..选择..."不工作 [英] Spring JdbcTemplate "insert into.. select from.." not working

查看:255
本文介绍了Spring JdbcTemplate“插入..选择..."不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spring JdbcTemplate执行以下SQL:

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.

当我尝试使用JdbcTemplate执行以下SQL时,它可以工作并在DB表中插入数据:

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');

下面是我要执行以上SQL的电话:

Below is my call to execute above SQLs:

jdbcTemplate.update(sqlString);

不知道这里出了什么问题.

Not sure what is going wrong here.

推荐答案

我不得不求助于普通JDBC,并且有效:

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

不知道为什么Spring JdbcTemplate无法处理这种事情!

Not sure why Spring JdbcTemplate can not handle such thing!

这篇关于Spring JdbcTemplate“插入..选择..."不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆