hi how do you do validation in java for primary key lets say the table got combination of two columns as primary key,how can i validate that if use enter already existing value
The database will do that automatically and raise an exception when the user tries to INSERT the rows in the table.
Your code should trap that exception and take appropriate action.
ok so how can i trap that exception so the use can see that error or display that with meaningful message not with ORA error
I dont' understand your question.
If you are asking how to write an exception handler see the 'Exceptions' trails in The Java Tutorials:
The Java programming language uses exceptions to handle errors and other exceptional events. This lesson describes when and how to use exceptions.
Create a simple test case that does an INSERT of a duplicate value and look at the displayed stack trace to see what exception got thrown.
Then create an exception handler to 'catch' that exception and substitute your own message.
- Add the integrity constraint to the table. I suggest that you explicitly name it.
- Test the database to figure out what exception it returns for that constraint. With luck the name you used will be in the text of the exception.
- Add a catch to your database layer that catches SQLException, looks for the error message, and then throws a different exception, probably your own.
- In your UI and/or webservice layer catch that specific exception and convert it to something appropriate.
The above presumes you have a basic understanding of java, try/catch, UI code, and how layers work.