So I have this working code/prepared statement that adds a username and password into a database, however I need to check if the username already exists in the code.
public void addUser(Connection conn, PreparedStatement pstmnt, String username, String password)
{
try
{
pstmnt = conn.prepareStatement("insert into users values (?,?,?)");
pstmnt.setInt(1, 0);
pstmnt.setString(2, username);
pstmnt.setString(3, password);
pstmnt.executeUpdate();
}
catch (SQLException e) { System.out.println("Error: " + e.getMessage()); }
System.out.println(username + " has been added");
}
Is there any simple way to do this?
uniqueconstraint in the database does not work?