Hi helper, I have incountered a problem catching an error. The error is a dublicate primary key that the user might want to insert into a db. I f he tries there an error raises up and i would like to catch this specific error. 1.What is the name of the exception that catchs this error? 2.Do you know of a source that might lead me to a list of exceptions in java? Thanks
The execption raise by a duplicate key is a java.sql.SQLException... like any other problem during a SQL query. Log the exception message to know why it crash. DUplicate primary key is a programatic exception, it is not suppose to happen in a well done program, so there is no specific exception for that problem
garfild: I see your problem here. Although you know it is a SQLException, you want to distinguish between different sql exceptions and take action only on a primary key violation. This can be done, but with some portability warnings. 1. Find out what the exact error message of the SQLException. 2. have a routine that checks for this specific error message. If it matches, then you know that you have your primary key violation exception and can act accordingly.
The portability issue here is that if you change databases or even drivers, the error messages will be different. This will introduce errors into the exception handling routines. Some other ideas are to centralize the error messages into one class. This may ease the transition to a new driver so you are not frantically checking thousands of lines of code changing all your hard coded messages to the new message. Jamie