Java Utililty Methods SQL ResultSet Read

List of utility methods to do SQL ResultSet Read

Description

The list of methods to do SQL ResultSet Read are organized into topic(s).

Method

intgetCountFromResultSet(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)
...
ListgetDateList(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;
...
DategetDbDateValue(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;
StringgetDebugData(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));
...
booleangetDuplicacy(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);
...
MapgetEntityMap(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;
...
EgetEnum(Class enumClass, ResultSet rs, String columnName)
get Enum
String value = rs.getString(columnName);
if (value == null) {
    return null;
} else {
    return Enum.valueOf(enumClass, value);
TgetEnum(ResultSet r, String columnName, Class enumType)
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;