List of utility methods to do SQL ResultSet Read
int | getCountFromResultSet(ResultSet rs) get Count From Result Set int count = -1; try { if (!rs.next()) { return -1; count = rs.getInt(1); } catch (SQLException ex) { System.out.println(ex.getMessage()); ... |
Object[][] | getData(final ResultSet rs) Get a ResultSet's result. final List<Object[]> resultList = new ArrayList<Object[]>(); final ResultSetMetaData md = rs.getMetaData(); final int columnCount = md.getColumnCount(); while (rs.next()) { final Object[] row = new Object[columnCount]; for (int i = 0; i < columnCount; i++) { row[i] = rs.getObject(i + 1); resultList.add(row); return resultList.toArray(OBJECT_ARRAY_ARRAY_INSTANCE); |
Map | getDataDupls(ResultSet rs) get Data Dupls Map<String, List<Integer>> mm = new HashMap<String, List<Integer>>(); List<Integer> li; int cc = rs.getMetaData().getColumnCount(); int j = 1; String prev = null; String next; while (j <= cc) { if (j > 1) ... |
List | getDateList(ResultSet resultSet, String columnName) Returns a list of date values using a given SQL result set and column name. List<Date> values = null; if (resultSet != null && columnName != null) { values = new ArrayList<Date>(); while (resultSet.next()) { values.add(getDate(resultSet, columnName)); return values; ... |
Date | getDbDateValue(ResultSet rs, String columnName) Given a ResultSet and a column name containing a [possibly null] Date , this method attempts to fetch the date from the result set.
Date retVal = null; try { Object o = rs.getObject(columnName); if (o != null) retVal = (Date) o; } catch (SQLException e) { throw new RuntimeException("Unable to get result set Date value for column '" + columnName + "'"); return retVal; |
String | getDebugData(ResultSet rs) Get some debug information to debug why an exception occurred. try { StringBuilder sb = new StringBuilder(); ResultSetMetaData rsmd = rs.getMetaData(); int colCount = rsmd.getColumnCount(); sb.append("#columns = " + colCount); for (int i = 0; i < colCount; i++) { sb.append(" | "); sb.append(rsmd.getColumnName(i + 1)); ... |
boolean | getDuplicacy(ResultSet rs) get Duplicacy int cc = rs.getMetaData().getColumnCount(); int j = 1; String prev = null; String next; while (j <= cc) { if (j > 1) prev = rs.getString(j - 1); next = rs.getString(j); ... |
Map | getEntityMap(ResultSet rs, ResultSetMetaData rsmd) get Entity Map Map<String, Object> entity = new HashMap<>(); int colCount = rsmd.getColumnCount(); for (int i = 0; i < colCount; i++) { String colName = rsmd.getColumnLabel(i + 1).toUpperCase(); Object colValue = rs.getObject(colName); entity.put(colName, colValue); return entity; ... |
E | getEnum(Class get Enum String value = rs.getString(columnName); if (value == null) { return null; } else { return Enum.valueOf(enumClass, value); |
T | getEnum(ResultSet r, String columnName, Class get Enum String name = r.getString(columnName); T val = null; if (name != null) { try { val = Enum.valueOf(enumType, name); } catch (java.lang.IllegalArgumentException e) { val = null; return val; |