Java Utililty Methods SQL ResultSet

List of utility methods to do SQL ResultSet

Description

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

Method

StringcreateUid(final String[] keys, final ResultSet rs, final String keySeparator)
create Uid
final StringBuilder uid = new StringBuilder();
if (keys != null && keys.length > 0) {
    for (String field : keys) {
        if (uid.length() > 0) {
            uid.append(keySeparator);
        uid.append(rs.getString(field));
return uid.toString();
ListencodeHeader(ResultSetMetaData metaData)
encode Header
ArrayList<String> res = new ArrayList<>();
res.add(Integer.toString(metaData.getColumnCount()));
for (int i = 1; i <= metaData.getColumnCount(); i++) {
    String columnName = metaData.getColumnName(i);
    String columnLabel = metaData.getColumnLabel(i);
    if (columnLabel == null || columnLabel.equalsIgnoreCase(columnName)) {
        res.add(columnName);
    } else {
...
OptionalextractGeneratedId(ResultSet generatedKeys)
extract Generated Id
if (generatedKeys.next()) {
    return Optional.of(generatedKeys.getLong(1));
return Optional.empty();
intextractIntResult(ResultSet rs, ResultSetMetaData rsmd, int index)
This method returns an int result at a given index.
int count = rsmd.getColumnCount();
if (index > count || index < 1) {
    throw new Exception("Invalid index");
int type = rsmd.getColumnType(index);
switch (type) {
case java.sql.Types.INTEGER:
case java.sql.Types.SMALLINT:
...
List>extractResults(ResultSet resultSet)
extract Results
List<Map<String, ?>> results = new ArrayList<Map<String, ?>>();
while (resultSet.next()) {
    Map<String, Object> row = new HashMap<String, Object>();
    for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
        row.put(resultSet.getMetaData().getColumnLabel(i), resultSet.getObject(i));
        results.add(row);
return results;
SetextractResultSetFiledNames(ResultSet result)
extract Result Set Filed Names
ResultSetMetaData rsmd = result.getMetaData();
Set<String> columnsSet = new HashSet<>();
int columns = rsmd.getColumnCount();
for (int x = 1; x <= columns; x++) {
    columnsSet.add(rsmd.getColumnName(x));
return columnsSet;
voidfillRowNames(Map metaData, ResultSet rs)
fill Row Names
Assert.notNull(metaData, "The column names can't be null.");
if (metaData.isEmpty()) {
    for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
        metaData.put(rs.getMetaData().getColumnName(i), rs.getMetaData().getColumnType(i));
booleanhasCompleted(ResultSet rs)
has Completed
try {
    return (rs.isClosed() || rs.isAfterLast());
} catch (SQLException e) {
    return false;
booleanhasGeometryField(ResultSet resultSet)
Check if the resultset contains a geometry field
ResultSetMetaData meta = resultSet.getMetaData();
int columnCount = meta.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
    if (meta.getColumnTypeName(i).equalsIgnoreCase("geometry")) {
        return true;
return false;
...
booleanisNull(ResultSet rs, String name)
is Null
rs.getObject(name);
return rs.wasNull();