public void createUser(final String name,final String email,final String hashedPassword,final boolean admin){
  final String validationErrors=validate(name,email,hashedPassword);
  if (validationErrors != null) {
    throw new IllegalStateException(validationErrors);
  }
  if (doesUserExist(name)) {
    throw new IllegalStateException("That user name has already been taken");
  }
  final Connection con=Database.getConnection();
  try {
    final PreparedStatement ps=con.prepareStatement("insert into ta_users (username, password, email, joined, lastLogin, admin) values (?, ?, ?, ?, ?, ?)");
    ps.setString(1,name);
    ps.setString(2,hashedPassword);
    ps.setString(3,email);
    ps.setTimestamp(4,new Timestamp(System.currentTimeMillis()));
    ps.setTimestamp(5,new java.sql.Timestamp(System.currentTimeMillis()));
    ps.setInt(6,admin ? 1 : 0);
    ps.execute();
    ps.close();
    con.commit();
  }
 catch (  final SQLException sqle) {
    if (sqle.getErrorCode() == 30000) {
      s_logger.info("Tried to create duplicate user for name:" + name + " error:"+ sqle.getMessage());
      throw new IllegalStateException("That user name is already taken");
    }
    s_logger.log(Level.SEVERE,"Error inserting name:" + name + " email: "+ email+ " pwd: "+ hashedPassword,sqle);
    throw new IllegalStateException(sqle.getMessage());
  }
 finally {
    DbUtil.closeConnection(con);
  }
}

public void createUser ( final String name , final String email , final String hashedPassword , final boolean admin ) { final String validationErrors = validate ( name , email , hashedPassword ) ; if ( validationErrors != null ) { throw new IllegalStateException ( validationErrors ) ; } if ( doesUserExist ( name ) ) { throw new IllegalStateException ( "That user name has already been taken" ) ; } final Connection con = Database . getConnection ( ) ; try { final PreparedStatement ps = con . prepareStatement ( "insert into ta_users (username, password, email, joined, lastLogin, admin) values (?, ?, ?, ?, ?, ?)" ) ; ps . setString ( 1 , name ) ; ps . setString ( 2 , hashedPassword ) ; ps . setString ( 3 , email ) ; ps . setTimestamp ( 4 , new Timestamp ( System . currentTimeMillis ( ) ) ) ; ps . setTimestamp ( 5 , new java . sql . Timestamp ( System . currentTimeMillis ( ) ) ) ; ps . setInt ( 6 , admin ? 1 : 0 ) ; ps . execute ( ) ; ps . close ( ) ; con . commit ( ) ; } catch ( final SQLException sqle ) { if ( sqle . getErrorCode ( ) == 30000 ) { s_logger . info ( "Tried to create duplicate user for name:" + name + " error:" + sqle . getMessage ( ) ) ; throw new IllegalStateException ( "That user name is already taken" ) ; } s_logger . log ( Level . SEVERE , "Error inserting name:" + name + " email: " + email + " pwd: " + hashedPassword , sqle ) ; throw new IllegalStateException ( sqle . getMessage ( ) ) ; } finally { DbUtil . closeConnection ( con ) ; } }
create a user in the database . if an error occured , an illegalstateexception will be thrown with a user displayable error message .
