java excel read sample

import java.io.FileInputStream;

import java.util.ArrayList;

import java.util.List;

 

import org.apache.poi.hssf.usermodel.HSSFSheet;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;

 

public class xlsReader {

 

public static void main(String[] args) throws Exception {

 

// TODO 自動生成されたメソッド・スタブ

 List <beanUser> lbu = new ArrayList<beanUser>();

 //Path of the excel file

 FileInputStream fs = new FileInputStream("userlistm.xls");

 //Creating a workbook XSSF for ver 2007 after

 HSSFWorkbook workbook = new HSSFWorkbook(fs);

 HSSFSheet sheet = workbook.getSheetAt(0);

 int cnt = 0;

 while(true) {

   beanUser bu = new beanUser();

   Row row = sheet.getRow(cnt);

   if(row==null) { 

   break;

   }

  Cell cell = row.getCell(0);

  System.out.println(cell.getAddress());

  bu.setId(cell.getStringCellValue());

  cell = row.getCell(1);

  bu.setName(cell.getStringCellValue());

  cell = row.getCell(2);

  bu.setAge(cell.getStringCellValue());

  cell = row.getCell(3);

  bu.setBirth(cell.getStringCellValue());

  lbu.add(bu);

  cnt++;

}

  lbu.stream().forEach(id -> System.out.println(id.getId()+

  id.getName()+id.getAge()+id.getBirth()));

 

}

 

}

postgresql trick by generate_series

select 

* 

from GENERATE_SERIES('2020-03-12'::timestamp, '2030-03-12'::timestamp, '6 month'::INTERVAL);

 

   generate_series   

---------------------

 2020-03-12 00:00:00

 2020-09-12 00:00:00

 2021-03-12 00:00:00

 2021-09-12 00:00:00

 2022-03-12 00:00:00

 2022-09-12 00:00:00

 2023-03-12 00:00:00

 2023-09-12 00:00:00

 2024-03-12 00:00:00

 2024-09-12 00:00:00

 2025-03-12 00:00:00

 2025-09-12 00:00:00

 2026-03-12 00:00:00

 2026-09-12 00:00:00

 2027-03-12 00:00:00

 2027-09-12 00:00:00

 2028-03-12 00:00:00

 2028-09-12 00:00:00

 2029-03-12 00:00:00

 2029-09-12 00:00:00

 2030-03-12 00:00:00

(21 rows)