title: check for duplicate data before insert
body: <p>I'm creating a java swing program where users can create a record, but I want to be able to check for duplicates before allowing the users to create the record. Here's my code:</p>
  
  <pre><code>public boolean createAssignRequest(AssignmentRequests assignReq) {
  
      int id = assignReq.getReqId();
      String dutyName = assignReq.getDutyName();
      String volNric = assignReq.getVolNric();
  
      boolean success = false;
      DBController db = new DBController();
      String dbQuery = "";
  
      db.getConnection();
  
      dbQuery = "INSERT into assignrequests (dutyName, volNric)"
              + " VALUES ('" + dutyName + "','" + volNric + "')";
  
      if (db.updateRequest(dbQuery) == 1) {
          success = true;
      }
      db.terminate();
  
      return success;
  
  }
  </code></pre>
  
  <p>whereby users cannot create the record if a row with the same dutyName and volNric already exists. 
  If I were to execute this line of sql statement</p>
  
  <pre><code>ALTER TABLE `assignrequests` ADD UNIQUE `uniqueindex`(`dutyName`, `volNric`);
  </code></pre>
  
  <p>would I implement it in mySQL (just one time even if i truncate my data) or in my program codes? (I'm using eclipse)
  I'm also using a three-tier architecture :-)
  Finally, how would I implement the code to show a JOptionPane if a duplicate record is already detected? Thanks for your help!</p>