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

booleanhasTableAndColumns(Connection conn, String tableName, String... colNames)
has Table And Columns
Collection<String> cols = new HashSet<String>();
for (String c : colNames) {
    if (c != null) {
        cols.add(c.toLowerCase());
return (hasColumns(conn, tableName, cols) || hasColumns(conn, tableName.toLowerCase(), cols)
        || hasColumns(conn, tableName.toUpperCase(), cols));
...
intindent_DisplayBanner(PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
inden Display Banner
StringBuffer buf = new StringBuffer();
int numCols = displayColumnWidths.length;
int rowLen;
rowLen = (numCols - 1); 
for (int i = 1; i <= numCols; i++)
    rowLen += displayColumnWidths[i - 1];
buf.ensureCapacity(rowLen);
for (int i = 1; i <= numCols; i++) {
...
booleanisColumnNullable(Connection conn, String table, String column)
Determines whether or not the specified column accepts null values.
ResultSet rs = getColumnMetaData(conn, table, column);
try {
    return rs.getString("IS_NULLABLE").equals("YES");
} finally {
    rs.close();
booleanisColumnNullable(Connection conn, String table, String column)
is Column Nullable
ResultSet rs = conn.getMetaData().getColumns(null, null, table, column);
if (rs.getMetaData().getColumnCount() > GET_COLUMNS_IS_NULLABLE) {
    if (!rs.next()) {
        return false;
    String val = rs.getString(GET_COLUMNS_IS_NULLABLE);
    return rs.getString(GET_COLUMNS_IS_NULLABLE).equals("YES");
return false;
booleanisNull(ResultSet resultSet, String columnName)
Validates if the supplied value is null from the result set.
return null == resultSet.getObject(columnName);
intlookupColumnIndex(final ResultSetMetaData resultSetMetaData, final String columnName)
lookup Column Index
if (columnName != null) {
    for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
        if (columnName.equalsIgnoreCase(lookupColumnName(resultSetMetaData, i))) {
            return i;
return 0;
...
intlookupColumnIndex(ResultSetMetaData resultSetMetaData, String name)
lookup Column Index
int columnCount = resultSetMetaData.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
    String columnName = resultSetMetaData.getColumnName(i);
    if (columnName.equals(name)) {
        return i;
return -1;
...
StringlookupColumnName(ResultSetMetaData resultSetMetaData, int columnIndex)
lookup Column Name
String name = resultSetMetaData.getColumnLabel(columnIndex);
if (name == null || name.length() < 1) {
    name = resultSetMetaData.getColumnName(columnIndex);
return name;
voidprintTableColumn(Connection conn, String sql)
print Table Column
Statement stmt = null;
ResultSet rs = null;
try {
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql);
    ResultSetMetaData metadata = rs.getMetaData();
    int columns = metadata.getColumnCount();
    for (int i = 1; i <= columns; i++) {
...
Double[][]readMultiDouble(ResultSet resultSet, String columnName)
Extracts a Double[][] field named columnName from current resultSet record
Double[][] doubleArray = null;
try {
    doubleArray = (Double[][]) resultSet.getArray(columnName).getArray();
} catch (SQLException x) {
return doubleArray;