LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-06-2008, 02:03 AM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 704

Rep: Reputation: 30
java: SQL duplicate key exception or query for key is faster


Hi,
i have to do some (hundreds of) INSERT operations in a database table. However, many of the data that are to be inserted, have already been inserted. Would it be faster to (1) wait for an SQL duplicate key exception or (2) to check the existence of the key by using a PreparedStatement query?
Is (2) faster than (1)?

Thanks
 
Old 01-06-2008, 04:32 AM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
My felling is that performing a Prepared select would be quicker than catching a duplicate insert error - as long as the table is indexed and the select uses the index. In addition this method is cleaner. I believe it will be quicker because Java will not have to create and handle the error for each duplicate: there must be a significant overhead with instantiating an exception object.

I support you could always perform a test on a smaller table to prove which is quicker. It would be interesting to see the timings of such a test.

Last edited by harry edwards; 01-06-2008 at 04:35 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Smart Key Signature ERRORS! How do I delete this bad key from my computer? Balarabay1 Linux - Software 4 09-27-2006 11:01 AM
Mysql Error: Duplicate entry '0' for key 1 w0lv3r1ne Linux - Server 1 08-17-2006 03:30 AM
SQL - getting the primary key autogenerated of an INSERT statement vharishankar Programming 3 12-05-2005 02:47 AM
duplicate gpg key issue Blackrose1 Linux - General 2 03-22-2004 09:33 AM
RSA public key encryption/private key decription koningshoed Linux - Security 1 08-08-2002 07:25 AM


All times are GMT -5. The time now is 11:22 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration