Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. public class ReadExcel {
  2.  
  3. HashMap<String, List<String>> result = new HashMap<String, List<String>>();
  4.  
  5. public HashMap<String, List<String>> process() {
  6. try
  7. {
  8. result.clear();
  9.  
  10. FileInputStream file = new FileInputStream(new File("C:/some.xlsx"));
  11.  
  12. //Create Workbook instance holding reference to .xlsx file
  13. XSSFWorkbook workbook = new XSSFWorkbook(file);
  14.  
  15. //Get first/desired sheet from the workbook
  16. XSSFSheet sheet = workbook.getSheetAt(0);
  17.  
  18. //Iterate through each rows one by one
  19. Iterator<Row> rowIterator = sheet.iterator();
  20.  
  21.  
  22. while (rowIterator.hasNext()) {
  23. List<String> xlsList = new ArrayList<String>();
  24.  
  25. Row row = rowIterator.next();
  26. Cell cell = row.getCell(1);
  27. Cell cell2 = row.getCell(2);
  28. String key ="";
  29. String value="";
  30. xlsList.clear();
  31. switch (cell.getCellType())
  32. {
  33. case Cell.CELL_TYPE_NUMERIC:
  34. key = getStringCellValue(cell);
  35. value = getNumericCellValue(cell2);
  36. break;
  37.  
  38. case Cell.CELL_TYPE_STRING:
  39. key = getStringCellValue(cell);
  40. value = getStringCellValue(cell2);
  41. break;
  42.  
  43. }
  44.  
  45. xlsList.add(value);
  46. result.put(key, xlsList);
  47. }
  48. }
  49. }
  50.  
  51. public class DB {
  52. HashMap<String, List<String>> result = new HashMap<String, List<String>>();
  53.  
  54. public HashMap<String, List<String>> process() {
  55.  
  56. result.clear();
  57.  
  58. Connection conn = null;
  59. Statement stmt = null;
  60. List<String> carColour = new ArrayList<String>();
  61.  
  62. try {
  63. Class.forName("oracle.jdbc.driver.OracleDriver");
  64. conn = DriverManager.getConnection(DB_URL, USER, PASS);
  65. stmt = conn.createStatement();
  66. String sql1 = "SOME SQL SELECT STATEMENT THAT RETURNS 2 or more lines, by that i mean "car" has 2 values or more";
  67. ResultSet rs = stmt.executeQuery(sql1);
  68.  
  69. while(rs.next()){
  70. carColour.add(rs.getString("colour")); // i select the column "colour"
  71. result.put("car", carColour); // i put "car" as key, and "blue" and "yellow" as values
  72. ...................................
  73. }
  74. } catch...
  75. }
  76.  
  77. final Map<String, Boolean> comparisonResult = compareEntries(dbResult, xlsResult);
  78. for(final Entry<String, Boolean> entry : comparisonResult.entrySet()){
  79. if (entry.getValue() == false){
  80. System.out.println("------------------------------------------------------------------------");
  81. System.out.println("| Comparison FAILED | Value not matching! Column name --> " + entry.getKey() + " |");
  82. }
  83. }
  84. System.out.println("------------------------------------------------------------------------");
  85. System.out.println("DB consistency check finished.");
  86.  
  87.  
  88. public static <K extends Comparable<? super K>, V>
  89. Map<K, Boolean> compareEntries(final Map<K, V> dbResult,
  90. final Map<K, V> xlsResult){
  91. final Collection<K> allKeys = new HashSet<K>();
  92. allKeys.addAll(dbResult.keySet());
  93. allKeys.addAll(xlsResult.keySet());
  94. final Map<K, Boolean> result = new TreeMap<K, Boolean>();
  95. for(final K key : allKeys){
  96. result.put(key, dbResult.containsKey(key) == xlsResult.containsKey(key) && Boolean.valueOf(equal(dbResult.get(key), xlsResult.get(key))));
  97. }
  98. return result;
  99. }
  100.  
  101. private static boolean equal(final Object obj1, final Object obj2){
  102. return obj1 == obj2 || (obj1 != null && obj1.equals(obj2));
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement