Results 1 to 4 of 4
  1. #1
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default trap primary key violation exception

    hi i have a table with two columns as primary key i what to trap exception if the use in UI try to enter duplication in the table i don't what to throw ORA ERROR i what to display meaningful error massage,my database is oracle 11g

    this is how i what to do it
    i what to add integrity constraint to the table, and i use explicitly name it.

    - i test the database to figure out what exception it returns for that constraint. With luck the name i used will be in the text of the exception.

    - i add a catch to my database layer that catches SQLException, looks for the error message, and then throws a different exception, probably my own message

    - In my UI layer catch that specific exception and convert it to something appropriate.

    has anyone done the above,will like some advise

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: trap primary key violation exception

    Use Hibernate?
    But, assuming that's not possible, parsing the error message is what Hibernate does in order to return a more meaningful exception.

    You could also look at the Hibernate code and see exactly how they do it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: trap primary key violation exception

    am using neat beans

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: trap primary key violation exception

    Your IDE is pretty irrelevant to the question.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 02-19-2012, 04:13 PM
  2. protocol violation error in jdbc connection
    By ronbigman in forum JDBC
    Replies: 0
    Last Post: 05-03-2011, 08:58 AM
  3. Check for unique key violation
    By andy16 in forum JDBC
    Replies: 6
    Last Post: 05-24-2010, 06:23 PM
  4. How to trap java process termination events?
    By thalupularavi in forum SWT / JFace
    Replies: 0
    Last Post: 03-10-2010, 03:02 PM

Posting Permissions

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