title: How can I avoid entering duplicate entries in my MySQL database?
body: <p>So, what I'm trying to do here is check the <code>user</code> table in my <code>users</code> mySQL database for duplicate entries in the <code>username</code> row, before inserting a new <code>username.</code> Here's an example of my code. Currently, the results ResultSet does not do anything and I'm not exactly sure how to implement it into the IF statement that follows.  And yes, I have the catches for the <code>try</code>, just not in this example. Sorry if this is a rather simple question, I just started programming with Java last week. Also, it's my first question on here and I definitely appreciate the help.</p>
  
  <pre><code> try{
  
  
        String sequel = ("SELECT username FROM `users`.`user`");
        PreparedStatement userNameInfo = conn.prepareStatement(sequel);
        userNameInfo.executeQuery(sequel);
        ResultSet results = userNameInfo.getResultSet();
  
        if (sequel.equals("")) {
            conn.setAutoCommit(false);
            String sql = "INSERT INTO `users`.`user`(`username`,`password`,`email`) VALUES('" + newusername +"', '" + newpassword + "', '" + newemail +"')";
            PreparedStatement prest = conn.prepareStatement(sql);
            prest.executeUpdate(sql);
            conn.commit();
            conn.close();
            System.out.println("Added Successfully!");
        }
        else {
            System.out.println("Add failed!");
        }
    }
  </code></pre>