title: Best practice to check duplicate value in database using java
body: <p>I set unique constraint for username using <code>@Column(unique=true)</code> 
  what would be the best practice to check duplicate value before inserting the data to database?</p>
  
  <ol>
  <li>By catching the exception which will throw by the program when you try to insert data having same username.</li>
  <li>Check database if the provided username is already exists before trying to insert.</li>
  </ol>