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

booleantableContainsColumn(Connection conn, String table, String column)
Returns true if the table with the specified name exists and contains a column with the specified name, false if either condition does not hold true.
boolean matched = false;
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)) {
        matched = true;
return matched;
booleantableContainsIndex(Connection conn, String table, String column, String index)
Returns true if the index on the specified column exists for the specified table, false if it does not.
boolean matched = false;
ResultSet rs = conn.getMetaData().getIndexInfo("", "", table, false, true);
while (rs.next()) {
    String tname = rs.getString("TABLE_NAME");
    String cname = rs.getString("COLUMN_NAME");
    String iname = rs.getString("INDEX_NAME");
    if (index == null) {
        if (tname.equals(table) && cname.equals(column)) {
...
ListtoColumnNameList(final ResultSet rs)
to Column Name List
final Map<Integer, String> columnNames = new TreeMap<Integer, String>();
while (rs.next()) {
    columnNames.put(rs.getInt("ORDINAL_POSITION"), rs.getString("COLUMN_NAME"));
return new ArrayList<String>(columnNames.values());
inttoFlag(ResultSetMetaData metaData, int column)
to Flag
int flags = 0;
if (metaData.isNullable(column) == 1) {
    flags |= 0001;
if (metaData.isSigned(column)) {
    flags |= 0020;
if (metaData.isAutoIncrement(column)) {
...
List>toFormatList(ResultSet results, List column)
to Format List
List<List<Object>> __return = new ArrayList<List<Object>>(128);
if (results == null)
    return __return;
ResultSetMetaData header = results.getMetaData();
List<Object> _tmp;
boolean writeFlag = false;
while (results.next()) {
    int i = 1;
...
MaptoMap(ResultSet rs, List wantedColumnNames)
to Map
Map columns = new LinkedHashMap();
int numWantedColumns = wantedColumnNames.size();
for (int i = 0; i < numWantedColumns; ++i) {
    List columnValues = new ArrayList();
    columns.put(wantedColumnNames.get(i), columnValues);
while (rs.next()) {
    for (int i = 0; i < numWantedColumns; ++i) {
...
ListtoValuesList(ResultSet results, String column)
to Values List
List<Object> valuesList = new ArrayList<Object>(128);
do {
    if (!results.next())
        break;
    Object value = results.getObject(column.toUpperCase());
    if (value != null)
        valuesList.add(value);
} while (true);
...