Business Magazine

ReadTheSQLfromExcel

Posted on the 07 August 2019 by Asik Ali @Asikali077

package com.WellsFargo.wim.Common;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.sample.read.BLSKYExchangeExl;
import com.sample.read.ReadExcel;

public class GetTestSQL {

private static final String FILE_NAME = “Actimize_Param_File.xlsx”;

public static List<String> readSQLFromExcel(String modelName) { //bluesky
List<String> returnValue = new ArrayList<String>();
try {

//FileInputStream excelFile = new FileInputStream(new File(FILE_NAME));

InputStream inputStream =ReadExcel.class.
getClassLoader().getResourceAsStream(FILE_NAME);

XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XSSFSheet datatypeSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = datatypeSheet.rowIterator(); //1000

while (iterator.hasNext()) { //1
int i=1;
Row currentRow = iterator.next();
if (currentRow.getRowNum() == 0) {
continue; // just skip the rows if row number is 0
}

returnValue=readEachRow(i, currentRow,modelName);
if(returnValue.size()>0) {
break;
}

}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return returnValue;
}

private static List<String> readEachRow(int i, Row currentRow,String expectedModelName) {
String modelName =currentRow.getCell(i++).getStringCellValue().toString();
List<String> returnValue= new ArrayList<String>();

if(modelName.equalsIgnoreCase(expectedModelName)) {
String odsSql =currentRow.getCell(i++).getStringCellValue().toString();
String udmStgSql =currentRow.getCell(i++).getStringCellValue().toString();
returnValue.add(odsSql);
returnValue.add(udmStgSql);

/*CompareTwoResultSet.getDataFromDB(odsSql, udmStgSql);

//BLSKYExchangeExl.getDataFromDB(odsSql);
*/

}
return returnValue;

}

}


Back to Featured Articles on Logo Paperblog