JDBC returns wrong number of affected rows

后端 未结 1 536
忘掉有多难
忘掉有多难 2020-12-19 22:35

If we have a table with 10 rows and we execute this query twice we get the wrong number of affected rows the second time.

Statement st = open();

st.executeU         


        
相关标签:
1条回答
  • 2020-12-19 23:35

    The JDBC specification apparently dictates that drivers have executeUpdate() return the number of rows found by the UPDATE statement, not the number of rows actually affected.

    To have MySQL Connector/J return the number of rows actually changed you can add the property useAffectedRows=true to your connection URL, although the documentation does warn that it is

    not JDBC-compliant, will break most applications that rely on "found" rows vs. "affected rows" for DML statements

    0 讨论(0)
提交回复
热议问题