cesar
cesar

Reputation: 9064

JDBC: best way to update a table?

Let's say that I get a ResultSet which was queryed using joins from an sql database.

Is it better to use an sql statement to update the tables or insert new tuples/rows?

Or should i use the resultSet.update() function?

I just want to know the drawbacks associated with each as well as the preferred method of updating tables.

Upvotes: 1

Views: 570

Answers (1)

ChssPly76
ChssPly76

Reputation: 100706

ResultSet will only be updatable if:

  1. You've created your statement with appropriate flag (ResultSet.CONCUR_UPDATABLE)
  2. The underlying database / driver supports updates over join results

If both conditions are true, updates are likely to be more efficient when done this way as you're already holding a cursor to the item. Otherwise you'll need to create a new statement - be sure to use a PreparedStatement for that.

Upvotes: 2

Related Questions