Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2004
    Posts
    62

    Unanswered: Can I insert ignore unique into a table?

    I' using java executeBatch. Can i iqnore unique key when i insert into the table

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    No, not possible. What's even worse: you can't even find out which record violated the constraint.

    executeBatch() is great because it is very fast (especially with the new 10g drivers) but it lacks decent error handling facilities.

    The only option you have, is to disable the constraint. Run your Java program. Then try to enable the constraint using the "EXCEPTIONS INTO" option, to identify the offending rows. After deleting those rows, you can enable the constraint.

    See the manual for ALTER TABLE for details on the ENABLE CONSTRAINT clause.

  3. #3
    Join Date
    Jul 2004
    Posts
    62
    Thanks for the reply,
    but i found a way to do that

    INSERT INTO clients
    (client_id, client_name, client_type)
    SELECT 10345, 'IBS', 'advertising'
    FROM dual
    WHERE not exists (select * from clients
    where clients.client_id = 10345);

  4. #4
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    Then your question was not properly ellaborated. I thought you were in need of something like DEFERRRED CONSTRAINTS.

  5. #5
    Join Date
    Jul 2004
    Posts
    62
    executeBatch() uses sql statement, therefore i have to manipulate the sql statement.

  6. #6
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by pakcik_kantin
    executeBatch() uses sql statement, therefore i have to manipulate the sql statement.
    Why do you use executeBatch() if you are only running one statement? Usually executeBatch() is used to "batch" several statements. If you are only running that single statement, executeUpdate() is the recommended method.

  7. #7
    Join Date
    Jul 2004
    Posts
    62
    Thanks sham for the fast replies.

    I have some kind like LOAD DATA INFILE process, i cannot use LOAD DATA INFILE therefore i use executeBatch(). Each line of the record i have to validate each field column and insert into database

    Sample records
    HUY7881788,TRACKINGHH,898-0890-788
    HUY7881781,TRACKINGHH,898-0890-788
    HUY7881788,TRACKINGHH,898-0890-788

    Each record must follow the system criteria which handled by java program. Our team has very limited access to the database server.

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •