Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ReadExcel {
- HashMap<String, List<String>> result = new HashMap<String, List<String>>();
- public HashMap<String, List<String>> process() {
- try
- {
- result.clear();
- FileInputStream file = new FileInputStream(new File("C:/some.xlsx"));
- //Create Workbook instance holding reference to .xlsx file
- XSSFWorkbook workbook = new XSSFWorkbook(file);
- //Get first/desired sheet from the workbook
- XSSFSheet sheet = workbook.getSheetAt(0);
- //Iterate through each rows one by one
- Iterator<Row> rowIterator = sheet.iterator();
- while (rowIterator.hasNext()) {
- List<String> xlsList = new ArrayList<String>();
- Row row = rowIterator.next();
- Cell cell = row.getCell(1);
- Cell cell2 = row.getCell(2);
- String key ="";
- String value="";
- xlsList.clear();
- switch (cell.getCellType())
- {
- case Cell.CELL_TYPE_NUMERIC:
- key = getStringCellValue(cell);
- value = getNumericCellValue(cell2);
- break;
- case Cell.CELL_TYPE_STRING:
- key = getStringCellValue(cell);
- value = getStringCellValue(cell2);
- break;
- }
- xlsList.add(value);
- result.put(key, xlsList);
- }
- }
- }
- public class DB {
- HashMap<String, List<String>> result = new HashMap<String, List<String>>();
- public HashMap<String, List<String>> process() {
- result.clear();
- Connection conn = null;
- Statement stmt = null;
- List<String> carColour = new ArrayList<String>();
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- conn = DriverManager.getConnection(DB_URL, USER, PASS);
- stmt = conn.createStatement();
- String sql1 = "SOME SQL SELECT STATEMENT THAT RETURNS 2 or more lines, by that i mean "car" has 2 values or more";
- ResultSet rs = stmt.executeQuery(sql1);
- while(rs.next()){
- carColour.add(rs.getString("colour")); // i select the column "colour"
- result.put("car", carColour); // i put "car" as key, and "blue" and "yellow" as values
- ...................................
- }
- } catch...
- }
- final Map<String, Boolean> comparisonResult = compareEntries(dbResult, xlsResult);
- for(final Entry<String, Boolean> entry : comparisonResult.entrySet()){
- if (entry.getValue() == false){
- System.out.println("------------------------------------------------------------------------");
- System.out.println("| Comparison FAILED | Value not matching! Column name --> " + entry.getKey() + " |");
- }
- }
- System.out.println("------------------------------------------------------------------------");
- System.out.println("DB consistency check finished.");
- public static <K extends Comparable<? super K>, V>
- Map<K, Boolean> compareEntries(final Map<K, V> dbResult,
- final Map<K, V> xlsResult){
- final Collection<K> allKeys = new HashSet<K>();
- allKeys.addAll(dbResult.keySet());
- allKeys.addAll(xlsResult.keySet());
- final Map<K, Boolean> result = new TreeMap<K, Boolean>();
- for(final K key : allKeys){
- result.put(key, dbResult.containsKey(key) == xlsResult.containsKey(key) && Boolean.valueOf(equal(dbResult.get(key), xlsResult.get(key))));
- }
- return result;
- }
- private static boolean equal(final Object obj1, final Object obj2){
- return obj1 == obj2 || (obj1 != null && obj1.equals(obj2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement