Example usage for java.sql ResultSet wasNull

List of usage examples for java.sql ResultSet wasNull

Introduction

In this page you can find the example usage for java.sql ResultSet wasNull.

Prototype

boolean wasNull() throws SQLException;

Source Link

Document

Reports whether the last column read had a value of SQL NULL.

Usage

From source file:org.opendatakit.persistence.engine.pgres.RelationRowMapper.java

@Override
public CommonFieldsBase mapRow(ResultSet rs, int rowNum) throws SQLException {

    CommonFieldsBase row;// w w w .  j  a va2s. c o  m
    try {
        row = relation.getEmptyRow(user);
        row.setFromDatabase(true);
    } catch (Exception e) {
        throw new IllegalStateException("failed to create empty row", e);
    }

    /**
     * Correct for the funky handling of nulls by the various accessors...
     */
    for (DataField f : relation.getFieldList()) {
        switch (f.getDataType()) {
        case BINARY:
            byte[] blobBytes = rs.getBytes(f.getName());
            row.setBlobField(f, blobBytes);
            break;
        case LONG_STRING:
        case URI:
        case STRING:
            row.setStringField(f, rs.getString(f.getName()));
            break;
        case INTEGER:
            long l = rs.getLong(f.getName());
            if (rs.wasNull()) {
                row.setLongField(f, null);
            } else {
                row.setLongField(f, Long.valueOf(l));
            }
            break;
        case DECIMAL: {
            String value = rs.getString(f.getName());
            if (value == null) {
                row.setNumericField(f, null);
            } else {
                row.setNumericField(f, new WrappedBigDecimal(value));
            }
        }
            break;
        case BOOLEAN:
            Boolean b = rs.getBoolean(f.getName());
            if (rs.wasNull()) {
                row.setBooleanField(f, null);
            } else {
                row.setBooleanField(f, b);
            }
            break;
        case DATETIME:
            Date d = rs.getTimestamp(f.getName());
            if (d == null) {
                row.setDateField(f, null);
            } else {
                row.setDateField(f, (Date) d.clone());
            }
            break;
        default:
            throw new IllegalStateException("Did not expect non-primitive type in column fetch");
        }
    }
    return row;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java

public static Integer getNullableInt32(ResultSet reader, int colidx) {
    try {/*  w  w w  .  jav  a 2s . com*/
        int val = reader.getInt(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Integer(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMySqlSchema.class, "getNullableInt32", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java

public static Integer getNullableUInt16(ResultSet reader, int colidx) {
    try {//from   www .  j  a  v  a2  s  . c  o m
        int val = reader.getInt(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Integer(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMySqlSchema.class, "getNullableUInt16", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java

public static Long getNullableUInt32(ResultSet reader, int colidx) {
    try {/*ww  w .j  a  va 2s .c  o  m*/
        long val = reader.getLong(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Long(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMySqlSchema.class, "getNullableUInt32", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java

public static Byte getNullableByte(ResultSet reader, int colidx) {
    try {/*from w w w .j ava 2 s .com*/
        byte val = reader.getByte(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Byte(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMySqlSchema.class, "getNullableByte", e);
    }
}

From source file:edu.ku.brc.specify.conversion.SynonymCleanup.java

/**
 * @param parentID/*  ww w  .  java  2s  . c  o m*/
 * @return family name or null
 * @throws SQLException 
 */
private String getFamilyName(final Integer parentID) {
    if (parentID != null) {
        PreparedStatement pLookupStmt = null;
        try {
            pLookupStmt = conn
                    .prepareStatement("SELECT RankID, FullName, ParentID FROM taxon WHERE TaxonID = ?");
            pLookupStmt.setInt(1, parentID);
            ResultSet rs = pLookupStmt.executeQuery();
            if (rs.next()) {
                int rankID = rs.getInt(1);
                String fullName = rs.getString(2);
                int newParentID = rs.getInt(3);
                boolean isParentNull = rs.wasNull();

                if (rankID == 140) {
                    return fullName != null ? fullName : NBSP;
                }

                if (rankID > 140 && !isParentNull) {
                    fullName = getFamilyName(newParentID);
                    if (StringUtils.isNotEmpty(fullName)) {
                        return fullName;
                    }
                }
            }
            rs.close();

        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (pLookupStmt != null)
                    pLookupStmt.close();
            } catch (SQLException e) {
            }
        }
    }
    return NBSP;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {// w  ww. j a v  a2s  . c o m
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMySqlSchema.class, "getNullableInt64", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java

public static String getNullableString(ResultSet reader, int colidx) {
    try {//from  ww w. j  ava2  s . co m
        String val = reader.getString(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (val);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMySqlSchema.class, "getNullableString", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java

public static BigDecimal getNullableUInt64(ResultSet reader, int colidx) {
    try {/*from www  . j  av a2s  .  c  om*/
        String strval = reader.getString(colidx);
        if (reader.wasNull() || (strval == null) || (strval.length() <= 0)) {
            return (null);
        } else {
            BigDecimal retval = new BigDecimal(strval);
            return (retval);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMySqlSchema.class, "getNullableUInt64", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java

public static Integer getNullableInt32(ResultSet reader, int colidx) {
    try {//from  ww  w  .  ja  v  a 2  s .  c  o  m
        int val = reader.getInt(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Integer(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMSSqlSchema.class, "getNullableInt32", e);
    }
}