Question: So I'm just trying to have registered users data show up in an SQL table. I know that I have successfully connected to the database but none of the data is being added. I am not sure why this is. When I do run the code it I get an SQLException about a duplicate entry 'username' for primary key. here's the code

```
public void createUser() throws SQLException{

    String query = " INSERT INTO users(username, password, name, email)"
            + " VALUES(?, ?, ?, ?)";
    PreparedStatement statement = db.getConn().prepareStatement(query);
    statement.setString(1, String.valueOf(username));
    statement.setString(2, String.valueOf(password));
    statement.setString(3, String.valueOf(name));
    statement.setString(4, String.valueOf(email));

        statement.executeUpdate();
      //  error is here
        statement.close();
        db.getConn().commit();
        System.out.println("success");

}

```

I'm able to print out all the username/password/name/email stuff no problem. The error is being thrown up on the `statement.executeUpdate()` line. 

here's the database being created. 

```
CREATE TABLE `users` (
`username` VARCHAR(45) NOT NULL,
`password` VARCHAR(45) NOT NULL, 
`name` VARCHAR(45) NOT NULL,
`email` VARCHAR(45) NOT NULL,
PRIMARY KEY(`username`))
COMMENT = "this is a test table";

```

I can insert data on MySQLWorkbench no problem and I can do `DESCRIBE users` and see the table with the users manually created in the workbench but I'm not sure why the java method isn't working. thanks for your time!

edit: changed from `statement.setString(1, "username");` to `statement.setString(1, String.valueOf(username));` and so on. but am now getting a data truncation error. `Data truncation: Data too long for column 'username' at row 1`

Answer: 
Your error is that you are inserting fixed values into the statement rather than your intended values.

```
statement.setString(1, "username");
    statement.setString(2, "password");
    statement.setString(3, "name");
    statement.setString(4, "email");

```

You shouldn't have quotes around the variable names. E,g:

```
statement.setString(1, username);
    statement.setString(2, password);
    statement.setString(3, name);
    statement.setString(4, email);

```
check table `user`,if there is `username` value of '1',drop it and try again.