Java SQL ResultSet Boolean Read getBoolean(ResultSet rs, String columnLabel)

Here you can find the source of getBoolean(ResultSet rs, String columnLabel)

Description

get Boolean

License

Apache License

Declaration

public static Boolean getBoolean(ResultSet rs, String columnLabel) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    public static Boolean getBoolean(ResultSet rs, String columnLabel) throws SQLException {
        String booleanString = getTrimmedString(rs, columnLabel);
        if ("1".equals(booleanString)) {
            return Boolean.TRUE;
        } else if ("0".equals(booleanString)) {
            return Boolean.FALSE;
        } else {//from w  w w.j a  v a2  s.c  om
            return null;
        }
    }

    public static String getTrimmedString(ResultSet rs, String columnLabel) throws SQLException {
        return nullIfEmpty(getString(rs, columnLabel));
    }

    public static String nullIfEmpty(String text) {
        return cleanLongText(text);
    }

    public static String getString(ResultSet rs, String columnLabel) throws SQLException {
        return rs.getString(columnLabel);
    }

    public static String cleanLongText(String text) {
        if (text != null) {
            String trimmedText = text.trim();
            if (trimmedText.length() > 0) {
                return trimmedText;
            }
        }

        return null;
    }
}

Related

  1. getBoolean(ResultSet res, String name)
  2. getBoolean(ResultSet resultSet, int columnIndex)
  3. getBoolean(ResultSet rs, int index)
  4. getBoolean(ResultSet rs, String colName)
  5. getBoolean(ResultSet rs, String columnName)
  6. getBoolean(ResultSet rs, String name)
  7. getBooleanFromResultSet(ResultSet rset, String field)
  8. getBooleanOrNull(ResultSet rs, String column)