You don't want any message if a violation occurs???
If you're not, I think that the best way to do this is a stored procedure
directly from the database. Case your RDBMS does not supports procedures, I
suggest you to create a function "insert" and before the insert use a "select
count(*) from table1 where col2 = id" statement to check if the record exists.