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:
- You've created your statement with appropriate flag (ResultSet.CONCUR_UPDATABLE)
- 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
2009-08-25 23:52:36
why use a prepared statement?
anonymous
2009-08-25 23:58:07
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
2009-08-26 00:00:32
+ 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
2009-08-26 00:04:28