PreparedStatement删除操作不起作用

时间:2020-08-04 12:04:52

标签: spring-boot hibernate jdbc spring-data-jpa prepared-statement

我正在使用NamedParameterJdbcTemplate这样从springboot应用程序的表中删除条目。

MapSqlParameterSource parameters = new MapSqlParameterSource();
            parameters.addValue("param1", "value1");
            parameters.addValue("listValues", "listOfValues");

String deleteSqlString = "DELETE
    FROM table1
    WHERE start_date >= to_date(:param1, 'yyyyMMdd')
    AND code    IN  (:listValues)"

Object result = paramJdbcTemplateFedb.execute(deleteSqlString, parameters,
                    new PreparedStatementCallback() {
                        public Object doInPreparedStatement(PreparedStatement ps)
                                throws SQLException, DataAccessException {
                            return ps.executeUpdate();
                        }
                    });

在这里,当涉及到 ps.executeUpdate()语句时,它将永远不会出现在该语句之外。而且执行永无止境,也没有错误。当我检查日志时,我得到了这样的信息。没有从数据源返回连接。

2020-08-04 12:16:04.377 DEBUG 39928 --- [nio-8443-exec-5] o.s.jdbc.datasource.DataSourceUtils      : Fetching JDBC Connection from DataSource
2020-08-04 12:16:04.442 DEBUG 39928 --- [-ClientPoller-0] org.apache.tomcat.util.net.NioEndpoint   : timeout completed: keys processed=1; now=1596523564442; nextExpiration=1596523563760; keyCount=0; hasEvents=false; eval=false
2020-08-04 12:16:04.517 TRACE 39928 --- [nio-8443-exec-5] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [20190110], value class [java.lang.String], SQL type unknown
2020-08-04 12:16:04.518 TRACE 39928 --- [nio-8443-exec-5] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 2, parameter value [20190110], value class [java.lang.String], SQL type unknown
2020-08-04 12:16:05.032 DEBUG 39928 --- [-ClientPoller-1] org.apache.tomcat.util.net.NioEndpoint   : timeout completed: keys processed=0; now=1596523565032; nextExpiration=1596523565032; keyCount=0; hasEvents=false; eval=false
2020-08-04 12:16:05.442 DEBUG 39928 --- [-ClientPoller-0] org.apache.tomcat.util.net.NioEndpoint   : timeout completed: keys processed=1; now=1596523565442; nextExpiration=1596523565442; keyCount=0; hasEvents=false; eval=false

这里连接永不返回。这是工作查询的日志。

2020-07-31 17:22:48.334 DEBUG 32340 --- [nio-8443-exec-6] o.s.jdbc.datasource.DataSourceUtils      : Fetching JDBC Connection from DataSource


  Delegating to parent classloader sun.misc.Launcher$AppClassLoader@18b4aac2
2020-07-31 17:22:49.450 DEBUG 32340 --- [nio-8443-exec-6] o.a.c.loader.WebappClassLoaderBase       :   --> Returning stream from parent
2020-07-31 17:22:49.465 DEBUG 32340 --- [nio-8443-exec-6] o.s.jdbc.datasource.DataSourceUtils      : Returning JDBC Connection to DataSource

但是其他读取查询正在运行。问题仅在于删除和更新。有什么建议可能是什么问题?

0 个答案:

没有答案
相关问题