Anyone ever seen this? I'm using MS SQL Server 2008, and I've tried it with two different JDBC drivers (jtds, and Microsoft's). I run a simple statement to update a row, and it does update it, but getUpdateCount
returns 0. If I try it for different tables, it returns 1 as expected. It's something about this one table.
PreparedStatement ps =
conn.prepareStatement("select count(*) from foo_users where user_id = 1")
ResultSet rs = ps.executeQuery();
rs.next()
println(" count(*) is " + rs.getInt(1)); // Prints 1
ps = conn.prepareStatement("update foo_users set is_admin = 1 where user_id = 1")
ps.execute()
int count = ps.getUpdateCount()
println(" update count is " + count) // Prints 0. WTF.
What is causing this?
Update in response to comment: Yes, executeUpdate
works. But I ask this question because I'm using a query library called jOOQ which is returning incorrect results because it's calling execute
and getUpdateCount
. I left this out of my question originally, because I don't think it is the library's fault.