Example #1
0
public class ExtractEmails
{
    
    /*
     * connect to database
     * execute SQL statement to retrieve domain IDs
          Could use database and SQL to do the heavy processing but that's easy
          SELECT date(now()),  substr(addr,locate('@',addr)+1) as maildomain, count (*) as mailcount FROM mailing GROUP BY maildomain ORDER BY mailcount DESC
          use simple SQL statement (do not truncate)
        
        restriction: simple SQL statement being used
          select * from mailing
        retrieve domain IDs and put them into list (or file)
        go through list and strip the local part of email out, save the domain (base on @)
        assume that the e-mails have already went through a validation/verification process before being put into the table
         
     */
    
    //initialize variables/constants
    
    //database objects/variables
    Connection con          = null;
    Statement qry           = null;
    Statement insert        = null;
    ResultSet rs            = null;
    String database         = "test_database";
    String username         = "******";
    String password         = "******";
    final String table1     = "mailing";
    final String table1C1   = "ADDR";
    final String table2     = "addresscount";
    //final String fileName   = ""      //figure out if need to insert by file or by sQL statement
    String SQLRetrive       = "SELECT * FROM " + table1;
    //String SQLLoad          = "LOAD DATA INFILE " + fileName + " INTO TABLE " + table2;       //figure out if need to insert by file or SQL statement
    
    //data variables
    List <String> emailList         = new ArrayList<String>();
    SimpleDateFormat dateFormat     = new SimpleDateFormat("MM-dd-YYYY");
    Calendar calDate                = Calendar.getInstance();
    String date                     = dateFormat.format(calDate);
    
    
    //Connect to database
    
    String strRS = null;
    Hashtable <String, Integer> domainCount = new Hashtable<String, Integer>();
    int i = 0;
    int dupEmailCount = 0;
    
    //execute SQL statement, SELECT * FROM mailing
    //rs = ...
    while (rs.next())
    {
        strRS = rs.getString(table1C1);
        strRS = strRS.substring(strRS.lastIndexOf("@")+1);
        emailList.add(strRS);
    }
    //sort list in alphabetical order (duplicates included)
    Collections.sort(emailList);
    
    for (i=0; i < emailList.length(); i++)
    {
        //create out of bounds exception emailList.get(-1)
        if (emailList.get(i) == emailList.get(i-1))
        {
            dupEmailCount++;
        }
        else
        {
            //insert domain email, dupEmailCount into hashtable
            domainCount.put(emailList.get(i), dupEmailCount);
            dupEmailCount = 0;
        }
    }
        
    //count the duplicates
    //use TreeSet as a solution?
    
    
    
}
Example #2
0
  static void MonthArray(int year) {
    String Month12[][] = new String[12][6];
    for (int month = 1; month < 13; month++) {
      int START_DAY_OF_WEEK = 0;
      int END_DAY = 0;
      String monthDate[] = {"", "", "", "", "", ""};

      Calendar sDay = Calendar.getInstance(); // 시작일
      Calendar eDay = Calendar.getInstance(); // 끝일

      // 월의 경우 0부터 11까지의 값을 가지므로 1을 빼주어야 한다.
      // 예를 들어, 2004년 11월 1일은 sDay.set(2004,10,1);과 같이 해줘야 한다.

      sDay.set(year, month - 1, 1);
      eDay.set(year, month, 1);

      // 다음달의 첫날에서 하루를 빼면 현재달의 마지막 날이 된다.
      // 12월 1일에서 하루를 빼면 11월 30일이 된다.
      eDay.add(Calendar.DATE, -1);

      // 첫 번재 요일이 무슨 요일인지 알아낸다.
      START_DAY_OF_WEEK = sDay.get(Calendar.DAY_OF_WEEK);
      // eDay에 지정된 날짜를 얻어온다.
      END_DAY = eDay.get(Calendar.DATE);

      // 해당 월의 1일이 어느 요일인지에 따라서 공백을 출력한다.
      // 만일 1일이 수요일이라면 공백을 세 번 찍는다. (일요일부터 시작)

      for (int i = 1; i < START_DAY_OF_WEEK; i++) {

        monthDate[0] += "   ";
      }

      int day = 1;
      for (int k = START_DAY_OF_WEEK - 1; k < 7; k++) {
        monthDate[0] += (((day < 10) ? "  " + day : " " + day));
        ++day;
      }

      int l = 1;
      int k = 0;
      for (int date = day; date <= END_DAY; date++) {

        monthDate[l] += (((date < 10) ? "  " + date : " " + date));
        k++;
        if (k % 7 == 0) {
          l++;
          k = 0;
        }
      }
      String lastline = monthDate[4];
      if (!(lastline.length() == 21)) {

        for (int last = k; last < 7; last++) {

          monthDate[4] += "   ";
        }
      } // 마지막주 날짜에 공백 넣기
      for (int j = 0; j < 6; j++) {
        Month12[month - 1][j] = monthDate[j];
      }
    } // MonthArray method끝

    for (int quarter = 0; quarter < 4; quarter++) {

      System.out.println();
      for (int i = 1; i < 4; i++) {
        System.out.print(
            "      "
                + year
                + "년"
                + (((quarter * 3 + i) < 10) ? "  " + (quarter * 3 + i) : " " + (quarter * 3 + i))
                + "월       ");
      }
      System.out.println();
      System.out.println(" SU MO TU WE TH FR SA   SU MO TU WE TH FR SA   SU MO TU WE TH FR SA");
      for (int i = 0; i < 6; i++) {

        System.out.print(Month12[quarter * 3][i]);
        System.out.print("  ");
        System.out.print(Month12[quarter * 3 + 1][i]);
        System.out.print("  ");

        System.out.print(Month12[quarter * 3 + 2][i]);

        System.out.println();
      }
    } // 달력 출력
  } // Month12[][]생성