views:

111

answers:

1

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.

+1  A: 

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.

ChssPly76
why use a prepared statement?
anonymous
Because prepared statements should pretty much always be used in place of regular ones - they can be cached / reused by the database resulting in better performance and they protect you from SQL injection attacks among other things.
ChssPly76
+ 1 - Yeah, baby. PreparedStatement is the only way to go. I'd be hard-pressed to think of a good reason NOT to use them.
duffymo