This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Batch Insert with generated keys deals duplicate entry on unique Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Batch Insert with generated keys deals duplicate entry on unique" Watch "Batch Insert with generated keys deals duplicate entry on unique" New topic
Author

Batch Insert with generated keys deals duplicate entry on unique

Assaf Mizarchi
Greenhorn

Joined: Apr 06, 2012
Posts: 1
I am using MySql with JDBC...the below is my table definition

CREATE TABLE `A` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`type` varchar(255) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unq` (`type`(50),`value`(50))
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

At the moment i am using statement in order to batch insert rows to that table with RETURN_GENERATED_KEYS option in order to relate the id to other table.

I want the ability to perform that operation but when / if DUPLICATE ENTRY occur ( the same combination of type & value ) to continue with the transaction as like nothing happens but still to get the generated keys, and if DUPLICATE ENTRY occur retrieve the existing key.

Thanks
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

If it's a transaction, usually one failure will cancel the entire transaction.


My Blog: Down Home Country Coding with Scott Selikoff
 
 
subject: Batch Insert with generated keys deals duplicate entry on unique
 
Similar Threads
Hibernate is driving me crazy !
Mapping ENUM('0', '1') or CHAR(0) for Boolean
How to restrict user against marking same event in multiple times
java.sql.SQLException: Invalid argument value: Duplicate entry '3' for key 1
How do I avoid duplicate inserts in YoutubeFeed table?