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

StringreadString(final ResultSet resultSet, final String columnName)
Helper function that exists primarily to fool poedit to stop localizing column names.
return resultSet.getString(columnName);
StringreadStringFromBlob(ResultSet resultSet, String columnLabel)
read String From Blob
try {
    Blob factoryBlob = resultSet.getBlob(columnLabel);
    return new String(factoryBlob.getBytes(1L, (int) factoryBlob.length()), StandardCharsets.UTF_8);
} catch (SQLException e) {
    throw new RuntimeException(e);
intresultSetAsCount(ResultSet rs, String countColumn)
result Set As Count
int count = 0;
if (rs != null) {
    try {
        while (rs.next()) {
            count = Integer.parseInt(rs.getString(countColumn));
    } catch (Exception e) {
        e.printStackTrace();
...
booleanresultSetContainsColumn(ResultSet rs, String column)
Scans through a result set's metadata in an attempt to find a column
ResultSetMetaData meta = rs.getMetaData();
int total = meta.getColumnCount();
for (int i = 1; i <= total; i++) {
    if (meta.getColumnName(i).equals(column)) {
        return true;
return false;
...
booleanresultSetHasColumn(ResultSet rs, String sColumnName)
Determines if a column exists within the given resultset
if (rs == null)
    return false;
ResultSetMetaData rsmd = rs.getMetaData();
int iCols = rsmd.getColumnCount();
for (int i = 1; i <= iCols; i++) 
    if (rsmd.getColumnName(i).equalsIgnoreCase(sColumnName))
        return true;
...
StringresultSetToOneColumnAsCommamaSeparatedString(ResultSet rs)
result Set To One Column As Commama Separated String
if (rs == null)
    return null;
try {
    ResultSetMetaData metaData = rs.getMetaData();
    int numberOfColumns = metaData.getColumnCount();
    if (numberOfColumns > 1)
        return null;
    StringBuilder columnValues = new StringBuilder(numberOfColumns);
...
ListresultSetToOneColumnAsList(ResultSet rs)
result Set To One Column As List
if (rs == null)
    return null;
try {
    ResultSetMetaData metaData = rs.getMetaData();
    int numberOfColumns = metaData.getColumnCount();
    if (numberOfColumns > 1)
        return null;
    List<Object> rows = new ArrayList<Object>(numberOfColumns);
...
StringresultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column)
result Set To String Format
StringBuilder sb = new StringBuilder();
ResultSetMetaData metadata = rs.getMetaData();
int colmumnCount = metadata.getColumnCount();
if (column) {
    for (int i = 1; i <= colmumnCount; i++) {
        sb.append(quote).append(metadata.getColumnName(i)).append(quote);
        if (i + 1 <= colmumnCount) {
            sb.append(separator);
...
ObjectresultSetValue(ResultSet resultSet, Class parameterClass, Object object, String columnLabel)
result Set Value
Object value = null;
if (parameterClass.equals(String.class)) {
    value = resultSet.getString(columnLabel);
} else if (parameterClass.equals(Integer.class)) {
    value = resultSet.getInt(columnLabel);
} else if (parameterClass.equals(Float.class)) {
    value = resultSet.getFloat(columnLabel);
} else if (parameterClass.equals(Long.class)) {
...
ResultSetretrieveCoulmns(String tableName, String columnArray[], Statement statement, long offset, long numberOfRecords)
retrieve Coulmns
String query = "select ";
for (String column : columnArray) {
    query = query + " " + column + " ,";
query = query.substring(0, query.length() - 1);
query = query + "from " + tableName + " Limit " + offset + ", " + numberOfRecords + ";";
return statement.executeQuery(query);