Reputation: 552
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 ?
Upvotes: 2
Views: 2061
Reputation: 21
I think part of it is how large is the resultset. If you are looping through 3 million records, I would use the rs.updateRow() rather than executing a query 3 million times.
Upvotes: 0
Reputation: 308763
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.
Upvotes: 1