我JdbcDaoSupport
在我的 DAO 中使用 Spring 并尝试使用以下查询更新记录。
String callersUpdateQuery = "update W67U999S a set pcrdattim= ? where exists (select b.CRDATTIM, b.RECORDCD, b.CRNODE, b.UNITCD, b.WRKTYPE from W03U999S b where a.PCRDATTIM = ? and a.CCRDATTIM = b.CRDATTIM and a.CRECORDCD = b.RECORDCD and a.CCRNODE = b.CRNODE and a.PRECORDCD = 'F' and a.PCRNODE = '01' and b.WRKTYPE = 'CALLER' and b.UNITCD=? and a.crecordcd='T')";
以下是应该更新表的代码:
int updatedRowsCount =getJdbcTemplate().update(callersUpdateQuery, new Object[]{newFolderCrdattim, crdattim, businessAreaName});
但是 getJdbcTemplate().update() 没有更新所需的行并将更新的行数返回为零。奇怪的是,当我在数据库端执行相同的 sql 查询时,记录正在更新。谁能猜出代码或查询有什么问题?
日志消息也显示正确的值,但不知何故,查询没有更新数据库:
21:04:01,288 DEBUG [org.springframework.jdbc.core.JdbcTemplate.execute] Executing prepared SQL statement [update W67U999S a set pcrdattim= ? where exists (select b.CRDATTIM, b.RECORDCD, b.CRNODE, b.UNITCD, b.WRKTYPE from W03U999S b where a.PCRDATTIM = ? and a.CCRDATTIM = b.CRDATTIM and a.CRECORDCD = b.RECORDCD and a.CCRNODE = b.CRNODE and a.PRECORDCD = 'F' and a.PCRNODE = '01' and b.WRKTYPE = 'CALLER' and b.UNITCD=? and a.crecordcd='T')]
21:04:01,288 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection] Fetching JDBC Connection from DataSource
21:04:01,288 DEBUG [org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver] Creating new JDBC DriverManager Connection to [jdbc:oracle:thin:@10.193.244.225:1521:AWD]
21:04:03,865 TRACE [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal] Setting SQL statement parameter value: column index 1, parameter value [2017-08-09-10.33.10.168480], value class [java.lang.String], SQL type unknown
21:04:03,865 TRACE [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal] Setting SQL statement parameter value: column index 2, parameter value [2017-07-20-04.22.20.893340], value class [java.lang.String], SQL type unknown
21:04:03,865 TRACE [org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal] Setting SQL statement parameter value: column index 3, parameter value [CS2XAA], value class [java.lang.String], SQL type unknown
21:04:04,115 DEBUG [org.springframework.jdbc.core.JdbcTemplate.doInPreparedStatement] SQL update affected 0 rows
21:04:04,131 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection] Returning JDBC Connection to DataSource