Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException:

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException:

    Hi all,
    This is the exception i m getting when trying to insert a record into a table of MySQL through Java JDBC :
    com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException: Duplicate entry '539763' for key 'PRIMARY'

    I checked with the table but i don't find any entry with this value

    The column on which the exception was raised is an auto_incremented and primary key at the database level.

    Not knowing what could be the issue.

    Can somebody help me in resolving this issues

    Thanks n Regards
    Raaj

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,264
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException:

    Based upon the error message you are trying to insert a duplicate value into a column which constrains the entries to be unique - its not JDBC which is raising the exception by MySQL. Are you defining the primary key column, or letting the database auto increment the value? Perhaps you might get a faster response on a dedicated MySQL forum

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException:

    Quote Originally Posted by copeg View Post
    Based upon the error message you are trying to insert a duplicate value into a column which constrains the entries to be unique - its not JDBC which is raising the exception by MySQL. Are you defining the primary key column, or letting the database auto increment the value? Perhaps you might get a faster response on a dedicated MySQL forum
    Hi ,
    Thanks for ur quick reply.

    The construction of the table is as follows:

    CREATE TABLE `customer_claim_history` (
    `customer_claim_history_id`INT(11) NOT NULL AUTO_INCREMENT,
    `customer_claim_id` INT(11) NULL ,
    `account_id` INT(11) NULL ,
    `provider_datatype_id` INT(11) NULL,
    `claim_number` VARCHAR(255) NULL,
    `invoice_number` VARCHAR(255) NULL,
    `normalized_data` MEDIUMTEXT NULL,
    `job_id` INT(11) NULL,
    PRIMARY KEY (`customer_claim_history_id`)
    )

    I found everything fine with MySQL. When i fired the following query in MYSQL "select MAX(customer_claim_history_id) from customer_claim_history" i got the result as

    '539762'

    but the exception says that com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException: Duplicate entry '539763' for key 'PRIMARY'

    I don't find any entry with the value '539763' in the above constructed table.


    Please help me in knowing what could be issue.

    Thanks n Regards
    Raaj

  4. #4
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException:

    Ever tried to change the primary key of int to integer?

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException:

    Quote Originally Posted by Luciano_Lopes View Post
    Ever tried to change the primary key of int to integer?
    Hey somebody please help me...i got stucked with this issue.

    Thanks n Regards

    Raaj

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,264
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException:

    As I mentioned, this is a mysql database issue and these forums are java forums - you might be better off posting in a mysql db forum. That being said, I'd recommend a) run mysqlcheck to check/repair/optimize the table, if that doesn't work the worst case scenario b) rebuild the table by dumping its contents and recreating/inserting the data

Similar Threads

  1. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    By i4ba1 in forum JDBC & Databases
    Replies: 2
    Last Post: August 23rd, 2011, 12:41 PM
  2. Methods and Exceptions
    By Mandraix in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 27th, 2011, 07:15 PM
  3. how to handle many more exceptions
    By shailaja in forum Member Introductions
    Replies: 1
    Last Post: December 27th, 2010, 12:02 AM
  4. How To add my own Exceptions
    By Newtojava in forum Object Oriented Programming
    Replies: 1
    Last Post: September 2nd, 2010, 07:43 AM
  5. Java Exceptions
    By Vinceisg0d in forum Java Theory & Questions
    Replies: 2
    Last Post: March 12th, 2010, 11:25 PM