Java Utililty Methods SQL Table Column

List of utility methods to do SQL Table Column

Description

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

Method

MapgetColumnLabelMap(ResultSet resultSet)
get Column Label Map
Map<String, Integer> map = new HashMap<String, Integer>();
try {
    ResultSetMetaData rsmd = resultSet.getMetaData();
    int columnCount = rsmd.getColumnCount();
    for (int i = 1; i <= columnCount; i++) {
        map.put(rsmd.getColumnLabel(i), 1);
} catch (Exception e) {
...
ResultSetgetColumnMetaData(Connection conn, String table, String column)
Helper function for #getColumnType , etc.
ResultSet rs = conn.getMetaData().getColumns("", "", table, column);
while (rs.next()) {
    String tname = rs.getString("TABLE_NAME");
    String cname = rs.getString("COLUMN_NAME");
    if (tname.equals(table) && cname.equals(column)) {
        return rs;
throw new SQLException("Table or Column not defined. [table=" + table + ", col=" + column + "].");
MapgetColumnName(boolean isShowRowNum, ResultSet rs)
get Column Name
Map<Integer, String> mapColumnName = new HashMap<Integer, String>();
int intStartIndex = 0;
if (isShowRowNum) {
    intStartIndex++;
    mapColumnName.put(0, "#");
ResultSetMetaData rsm = rs.getMetaData();
int columnCount = rsm.getColumnCount();
...
StringgetColumnName(ResultSetMetaData meta, int column)
get Column Name
try {
    return meta.getColumnLabel(column);
} catch (SQLException e) {
    return meta.getColumnName(column);
ListgetColumnNames(final ResultSet resultSet)
get Column Names
final ResultSetMetaData meta = resultSet.getMetaData();
final List<String> result = new ArrayList<String>();
for (int i = 0; i < meta.getColumnCount(); i++) {
    result.add(meta.getColumnName(1 + i));
return result;
String[]getColumnNames(ResultSet resultSet_)
get Column Names
if (resultSet_ == null)
    return null;
ResultSetMetaData metaData = resultSet_.getMetaData();
int columnCount = metaData.getColumnCount();
if (columnCount < 1)
    return null;
String[] columnNames = new String[columnCount];
for (int i = 1; i <= columnCount; i++) {
...
String[]getColumnNames(ResultSet rs)
Retorna um array de strings com os nomes das colunas de um ResultSet
ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount();
String[] columnNames = new String[numColumns];
for (int i = 1; i < numColumns + 1; i++)
    columnNames[i - 1] = rsmd.getColumnName(i);
return columnNames;
ListgetColumnNames(ResultSet rs)
Returns the name of all the columns present in the specified ResultSet
final ResultSetMetaData metadata = rs.getMetaData();
final int count = metadata.getColumnCount();
final List<String> columnNames = new ArrayList<>(count);
for (int i = 0; i < count; ++i) {
    columnNames.add(metadata.getColumnLabel(i + 1).toLowerCase());
return columnNames;
String[]getColumnNames(ResultSet rs)
get Column Names
return getColumnNames(rs, false);
String[]getColumnNamesFromResultSet(ResultSet rs)
get Column Names From Result Set
String[] columnNames = new String[rs.getMetaData().getColumnCount()];
for (int i = 0; i < columnNames.length; i++)
    columnNames[i] = rs.getMetaData().getColumnName(i + 1);
return columnNames;