> You missed the simplest (and probably cleanest) option:
>
> int updateCount = update_by_key();
> if (updateCount == 0) insert_with_key();
> else if (updateCount > 1) yikes();
I think this depends on what you expect to happen more often: the insert or the
update. If most of the data is already present then I'd do the update first,
else the insert.
But first checking for the presence using SELECT is definitely much slower.
Thomas
Silvio Bierman - 04 Jun 2004 13:45 GMT
> > You missed the simplest (and probably cleanest) option:
> >
[quoted text clipped - 9 lines]
>
> Thomas
That is true but since checking the SQLException in such a way that you can
determine whether the key simply was already there or a more dramatic error
occurred is quite awkward I would only do this if updates are really seldom.
Regards,
Silvio