Exemplo n.º 1
0
  /** @param args */
  private static void registerStudents() throws Exception {
    Scanner keyboard = new Scanner(System.in);
    Class.forName("com.mysql.jdbc.Driver");
    Properties config = DBUtil.getConfigProperties();
    Connection conn = DBUtil.connectToDatabase(config, "cloudcoder.db");

    List<Course> courses =
        DBUtil.getAllModelObjects(
            conn,
            Course.SCHEMA,
            new IFactory<Course>() {
              @Override
              public Course create() {
                return new Course();
              }
            });
    Course c =
        ConfigurationUtil.choose(
            keyboard, "For which course would you like to register students?", courses);
    // TODO: look up the term for each course
    String filename =
        ConfigurationUtil.ask(
            keyboard,
            "Enter the name of the file containing a tab-separated list student registration entries in this format: \n"
                + "username\tfirstname\tlastname\temail\tpassword\tsection\n"
                + "Usernames in the datbase will be re-used, but the names/email/password will not be updated,"
                + "and users will not be registered for a course if they are already registered");
    int num =
        ConfigurationUtil.registerStudentsForCourseId(
            new FileInputStream(filename), c.getId(), conn);
    System.out.println("Registered " + num + " students for " + c.getName());
  }