Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / June 2004

Tip: Looking for answers? Try searching our database.

Performance

Thread view: 
Marco Schwarz - 04 Jun 2004 10:45 GMT
Hi,

I'm new in this newsgroup and perhaps I have a simple question ...

I writing a programm that push data from db1 to db2.

What is faster?

    select * from table1 where id = x
    if ( resultset.next() )
        update
    else
        insert

or

    try {
        insert
    } catch (sqlexcption e) {
        update
    }

 Cheers!
Marco
Sampsa Sohlman - 04 Jun 2004 10:57 GMT
> Hi,
>
[quoted text clipped - 17 lines]
>         update
>     }

What about following.

http://dataset.sohlman.com/SynchronizationTutorial.html

It reads all data to memory and then compare it and after that saves
changes to destination db.

- Sampsa

Signature

    -------------------------------------------
   // Sampsa Sohlman                        //
  //  My email can be found on my homepage //
 //   http://sampsa.sohlman.com           //
-------------------------------------------

Silvio Bierman - 04 Jun 2004 13:08 GMT
> Hi,
>
[quoted text clipped - 20 lines]
>   Cheers!
> Marco

You missed the simplest (and probably cleanest) option:

int updateCount = update_by_key();
if (updateCount == 0) insert_with_key();
else if (updateCount > 1) yikes();
Thomas Kellerer - 04 Jun 2004 13:15 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.