Exemplo n.º 1
0
  public void executeJob(Connection con) throws Exception {
    // input ����
    String fileName = "./기초자료/기초자료.xls";
    String sheetName = "GHOST_TABLES";
    FileInputStream fis = null;
    HSSFWorkbook wb = null;
    HSSFSheet sheet = null;

    // output ����
    String deleteSQL = "delete from ghost_tables";
    String insertSQL = "insert into ghost_tables values(?,?,?)";
    PreparedStatement pstmt = null;
    Statement stmt = null;

    try {
      // Input �ڷ� �غ�
      fis = new FileInputStream(fileName);
      wb = new HSSFWorkbook(fis);
      sheet = wb.getSheet(sheetName);

      // �����ڷ� All ����
      stmt = con.createStatement();
      stmt.execute(deleteSQL);

      // Insert�� SQL Statement ����
      pstmt = con.prepareStatement(insertSQL);

      HSSFRow row = null;
      Bean bean = null;

      for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
        row = sheet.getRow(i);
        readCount++;

        if (row == null) continue;

        bean = getBean(row);
        pstmt.setString(1, bean.tableName);
        pstmt.setString(2, bean.tableDesc);
        pstmt.setString(3, bean.shortName);
        pstmt.executeUpdate();
        writeCount++;

        System.out.printf("[%d][%s][%s][%s]\n", i, bean.tableName, bean.tableDesc, bean.shortName);
      }
    } finally {
      if (wb != null) wb.close();
      if (fis != null) fis.close();
      JDBCUtil.close(stmt);
      JDBCUtil.close(pstmt);
    }
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws Exception {
    // DB����
    Connection con = DBServer.getMysqlConnection();
    con.setAutoCommit(false);

    try {
      B1001 b = new B1001();
      b.executeJob(con);
      con.commit();
    } catch (Exception e) {
      con.rollback();
      throw e;
    } finally {
      JDBCUtil.close(con);
    }

    System.out.printf("<<Gooooood Job!!!>>\n");
    System.out.printf("Data Read Count -----[%d]\n", readCount);
    System.out.printf("Data Write Count ----[%d]\n", writeCount);
  }