jdbcTemplate.update freezes

蓝咒 提交于 2019-12-11 06:33:58

问题


I'm using a Spring JdbcTemplate without a "transactionManager" since I have mostly select to do.

When I try to call select queries from JUnit, it works, but when I try to call an "update", it freezes the test (no connection timeout, nothing, just waiting).

I've seen examples of jdbcTemplates insert/update without any transactionManager, but could it be the problem here ?

  public void insert(String param1, String param2) {

    String sql = "UPDATE MYTABLE SET name = :param1 where first_name = :param2";

    NamedParameterJdbcTemplate npJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
    SqlParameterSource namedParameters = new MapSqlParameterSource().addValue("param1", param1).addValue("param2", param2);

    npJdbcTemplate.update(sql, namedParameters);
  }

回答1:


The problem here was I had passed the same update query on the same line in a SQL client (Oracle SQL developer) but it had not been committed in this client.

My JUnit had been stalled for 12 hours and right after I commit the query in SQL developer, the update occurred in the JUnit.

It had nothing to do with transaction management in the app or autocommit status of the datasource.



来源:https://stackoverflow.com/questions/52954823/jdbctemplate-update-freezes

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