When inserting or updating data in DB (Oracle DB in my case) using Java, which is better to use:
ResultSet.insertRow()
, ResultSet.updateRow()
orStatement.executeUpdate(....)
Most of the time I use rs.insertRow()
and rs.updateRow()
, in that way avoiding the need to write queries, but is that justified performance-wise ?
I never do anything with ResultSet
except walk through it, map it into objects or data structures, and close it. If I want to INSERT, I do it with PreparedStatement
. My ResultSets
never stick around long enough to be modified. I prefer to keep persistence operations short so I can close the connection as quickly as possible. I think this approach scales better, because it's easier for multiple users to share pooled connections that way.