58 lines
1.7 KiB
Java
58 lines
1.7 KiB
Java
package org.sadigit.util;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSetMetaData;
|
|
import java.util.*;
|
|
|
|
|
|
@Slf4j
|
|
public class AppUtil {
|
|
|
|
public static List<Map<String, String>> convertResultsetToListStr(ResultSet rs) {
|
|
List<Map<String, String>> lst = new ArrayList<Map<String, String>>();
|
|
try {
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
int colCount = rsmd.getColumnCount();
|
|
String value = "";
|
|
|
|
while (rs.next()) {
|
|
HashMap<String, String> map = new HashMap<String, String>();
|
|
for (int i = 1; i <= colCount; i++) {
|
|
try {
|
|
if (rs.getObject(i).toString().equals("") || rs.getObject(i).toString().equals("null")) {
|
|
value = "";
|
|
} else {
|
|
value = rs.getObject(i).toString();
|
|
}
|
|
} catch (Exception e) {
|
|
value = "";
|
|
}
|
|
map.put(rsmd.getColumnName(i).toLowerCase(), value);
|
|
}
|
|
lst.add(map);
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
log.info("AppUtil :" + ex.getMessage());
|
|
}
|
|
|
|
return lst;
|
|
}
|
|
|
|
public static Double doubleNVL(Double value) {
|
|
return Optional.ofNullable(value).orElse(Double.NaN);
|
|
}
|
|
|
|
public static BigDecimal BigDecimalNVL(BigDecimal value) {
|
|
return Optional.ofNullable(value).orElse(null);
|
|
}
|
|
|
|
public static int intNVL(int value) {
|
|
return Optional.ofNullable(value).orElse(Integer.BYTES);
|
|
}
|
|
|
|
}
|