@Override public void createUser(User user) throws SQLException {
  String skeleton;
  if (user.isPrivileged()) {
    skeleton="grant all on *.* to %s@'%%' identified by '%s' with grant option";
    String sql=String.format(skeleton,user.getLogin(),user.getPassword());
    execute(sql);
  }
 else {
    skeleton="grant select on *.* to %s@'%%' identified by '%s' with grant option";
    String sql=String.format(skeleton,user.getLogin(),user.getPassword());
    execute(sql);
    Statement stmt=null;
    ResultSet rs=null;
    String currentSchema=null;
    try {
      stmt=dbConn.createStatement();
      rs=stmt.executeQuery("select database() as \"database\"");
      while (rs.next()) {
        currentSchema=rs.getString("database");
      }
    }
  finally {
      if (rs != null)       rs.close();
      if (stmt != null)       stmt.close();
    }
    skeleton="grant all on %s.* to %s@'%%' identified  by '%s' with grant option";
    String sql2=String.format(skeleton,currentSchema,user.getLogin(),user.getPassword());
    execute(sql2);
  }
}

@ Override public void createUser ( User user ) throws SQLException { String skeleton ; if ( user . isPrivileged ( ) ) { skeleton = "grant all on *.* to %s@'%%' identified by '%s' with grant option" ; String sql = String . format ( skeleton , user . getLogin ( ) , user . getPassword ( ) ) ; execute ( sql ) ; } else { skeleton = "grant select on *.* to %s@'%%' identified by '%s' with grant option" ; String sql = String . format ( skeleton , user . getLogin ( ) , user . getPassword ( ) ) ; execute ( sql ) ; Statement stmt = null ; ResultSet rs = null ; String currentSchema = null ; try { stmt = dbConn . createStatement ( ) ; rs = stmt . executeQuery ( "select database() as \"database\"" ) ; while ( rs . next ( ) ) { currentSchema = rs . getString ( "database" ) ; } } finally { if ( rs != null ) rs . close ( ) ; if ( stmt != null ) stmt . close ( ) ; } skeleton = "grant all on %s.* to %s@'%%' identified  by '%s' with grant option" ; String sql2 = String . format ( skeleton , currentSchema , user . getLogin ( ) , user . getPassword ( ) ) ; execute ( sql2 ) ; } }
creates a user that can connect from any location . if the user is a superuser , grant all on * . * , otherwise just grant select .
