【问题标题】:executeUpdate returning number of rows rather than affected rowsexecuteUpdate 返回行数而不是受影响的行
【发布时间】:2017-10-31 09:02:45
【问题描述】:
PreparedStatement updatestmt1 = con.prepareStatement("update BASE_TX set tx_vl=replace(tx_vl,?,?)");
                    updatestmt1.setString( 1, "${parm:"+ stringToreplace.trim() +"}" );
                    updatestmt1.setString( 2, "${parm:" + replacedString.trim() + "}" );

                    int ifUpdated1 = updatestmt1.executeUpdate();

ifUpdated1 返回 14480 而不是受影响的行数,在我运行的情况下,受影响的行数没有。因此,无论他们是否真的更新,我都无法拨打电话。

【问题讨论】:

  • 是的,这就是它应该做的。如果你想让它计算不同的东西,你需要添加一个 where 子句。

标签: java sql prepared-statement execute


【解决方案1】:

这是正确的行为。由于您没有设置WHERE,因此所有行都会受到影响。您的替换是身份这一事实与数据库无关。如果您真的想获得受影响的行,请像这样使用where

"update BASE_TX set tx_vl=replace(tx_vl,?,?) where tx_vl != replace(tx_vl,?,?)"

请注意,这会减慢您的查询速度,但会减少 IO,这实际上对您而言可能会更好。

【讨论】:

  • 如何减少IO?
猜你喜欢
  • 2013-07-08
  • 1970-01-01
  • 2015-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-24
  • 2016-02-01
  • 1970-01-01
相关资源
最近更新 更多