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

List>getRows(final ResultSet rs)
For SciDB, use getRowsSciDB instead This does not work with SciDB because for SciDB's JDBC reference to "getObject" invariably returns null.
if (rs == null) {
    return null;
List<List<String>> rows = new ArrayList<>();
try {
    ResultSetMetaData rsmd = rs.getMetaData();
    int NumOfCol = rsmd.getColumnCount();
    while (rs.next()) {
...
intgetRows(ResultSet table)
Get the number of rows in table.
if (table == null)
    return 0;
int rows;
try {
    table.last();
    rows = table.getRow();
} finally {
    table.beforeFirst();
...
String[]getRsCloumns(ResultSet rs)
get Rs Cloumns
ResultSetMetaData rsm = rs.getMetaData();
String[] columns = new String[rsm.getColumnCount()];
for (int i = 0; i < columns.length; i++) {
    columns[i] = rsm.getColumnLabel(i + 1);
return columns;
ObjectgetRSData(ResultSet rs, String columnName, int jdbcType)
get RS Data
if (jdbcType == Types.BIT || jdbcType == Types.BOOLEAN) {
    return rs.getByte(columnName);
} else {
    return rs.getObject(columnName);
StatementgetStatement(ResultSet resultSet)
get Statement
try {
    return resultSet.getStatement();
} catch (SQLException e) {
    throw new RuntimeException("Error getting statement from result set", e);
URIgetURI(ResultSet resultSet, String columnLabel)
get URI
return toURI(resultSet.getString(columnLabel));
URIgetURI(ResultSet rs, int col)
get URI
String o = rs.getString(col);
if (o == null) {
    return null;
try {
    return new URI((String) o);
} catch (Throwable t) {
    throw new UnsupportedOperationException("converting " + o.getClass().getName() + " " + o + " to URI",
...
UUIDgetUUIDFromResultSet(ResultSet rset, String name)
get UUID From Result Set
String val = rset.getString(name);
if (val != null && !val.isEmpty())
    return UUID.fromString(rset.getString(name));
return null;
ObjectgetValue(int type, ResultSet resultSet, int columnIndex)
get Value
switch (type) {
case Types.BLOB:
    return resultSet.getBytes(columnIndex);
case Types.CLOB:
    return resultSet.getString(columnIndex);
default:
    return resultSet.getObject(columnIndex);
StringgetValue(ResultSet result, String strField)
get Value
String strValueReturn = result.getString(strField);
if (result.wasNull())
    strValueReturn = "";
return strValueReturn;