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:io.kahu.hawaii.util.spring.AbstractDBRepository.java

protected Float getFloat(final ResultSet rs, final String columnLabel) throws SQLException {
    float result = rs.getFloat(columnLabel);
    return rs.wasNull() ? null : result;
}

From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java

protected Boolean getBoolean(final ResultSet rs, final int columnIndex) throws SQLException {
    boolean result = rs.getBoolean(columnIndex);
    return rs.wasNull() ? null : result;
}

From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java

protected Double getDouble(final ResultSet rs, final String columnLabel) throws SQLException {
    double result = rs.getDouble(columnLabel);
    return rs.wasNull() ? null : result;
}

From source file:io.kahu.hawaii.util.spring.AbstractDBRepository.java

protected Boolean getBoolean(final ResultSet rs, final String columnLabel) throws SQLException {
    boolean result = rs.getBoolean(columnLabel);
    return rs.wasNull() ? null : result;
}

From source file:dk.netarkivet.common.utils.DBUtils.java

/**
 * Get a Date from a column in the resultset.
 * Returns null, if the value in the column is NULL.
 * @param rs the resultSet//from  w  ww.java 2s. co m
 * @param columnIndex The given column, where the Date resides
 * @return a Date from a column in the resultset
 * @throws SQLException If columnIndex does not correspond to a
 * parameter marker in the ResultSet, or a database access error
 * occurs or this method is called on a closed ResultSet
 */
public static Date getDateMaybeNull(ResultSet rs, final int columnIndex) throws SQLException {
    ArgumentNotValid.checkNotNull(rs, "ResultSet rs");
    ArgumentNotValid.checkNotNegative(columnIndex, "int columnIndex");

    final Timestamp startTimestamp = rs.getTimestamp(columnIndex);
    if (rs.wasNull()) {
        return null;
    }
    Date startdate;
    if (startTimestamp != null) {
        startdate = new Date(startTimestamp.getTime());
    } else {
        startdate = null;
    }
    return startdate;
}

From source file:org.openmrs.module.xreports.api.db.hibernate.HibernateXReportsDAO.java

/**
 * @see org.openmrs.module.xreports.api.db.XReportsDAO#getSqlIntValue(java.lang.String)
 *//*from   w  w  w  .  j a v a  2s  .  c  om*/
@Override
public Integer getSqlIntValue(String sql) throws Exception {
    Integer value = null;
    Statement statement = sessionFactory.getCurrentSession().connection().createStatement();
    ResultSet res = statement.executeQuery(sql);
    if (res.next()) {
        value = res.getInt(1);
        if (res.wasNull()) {
            value = null;
        }
    }
    res.close();
    statement.close();
    return value;
}

From source file:com.opengamma.masterdb.security.hibernate.EnumUserType.java

@Override
public Object nullSafeGet(ResultSet resultSet, String[] columnNames, Object owner)
        throws HibernateException, SQLException {
    String databaseValue = resultSet.getString(columnNames[0]);
    if (resultSet.wasNull()) {
        return null;
    }/*from w ww.  j a  v a 2 s .c om*/
    return stringToEnum(databaseValue);
}

From source file:com.opengamma.masterdb.security.hibernate.ExpiryAccuracyUserType.java

@Override
public Object nullSafeGet(ResultSet resultSet, String[] columnNames, Object owner)
        throws HibernateException, SQLException {
    Integer databaseValue = resultSet.getInt(columnNames[0]);
    if (resultSet.wasNull()) {
        return null;
    }//w w w  .j ava 2 s  .co m
    switch (databaseValue) {
    case 1:
        return ExpiryAccuracy.YEAR;
    case 2:
        return ExpiryAccuracy.MONTH_YEAR;
    case 3:
        return ExpiryAccuracy.DAY_MONTH_YEAR;
    case 4:
        return ExpiryAccuracy.HOUR_DAY_MONTH_YEAR;
    case 5:
        return ExpiryAccuracy.MIN_HOUR_DAY_MONTH_YEAR;
    default:
        return null;
    }
}

From source file:org.jpos.ee.usertype.JsonType.java

/**
 * Retrieve an instance of the mapped class from a JDBC resultset. Implementors
 * should handle possibility of null values.
 *
 * @param rs      a JDBC result set/*  www .ja  v a  2s . co m*/
 * @param names   the column names
 * @param session
 * @param owner   the containing entity  @return Object
 * @throws HibernateException
 * @throws SQLException
 */
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
        throws HibernateException, SQLException {
    String json = rs.getString(names[0]);
    if (rs.wasNull())
        return null;
    try {
        return mapper.readTree(json);
    } catch (IOException e) {
        return new HibernateException("unable to read object", e);
    }
}

From source file:dk.netarkivet.common.utils.DBUtils.java

/** Execute an SQL statement and return the list of strings -> id mappings
 * in its result set.//  ww  w.ja v  a 2 s. c  o  m
 *
 * NB: the provided connection is not closed.
 *
 * @param connection connection to the database.
 * @param query the given sql-query (must not be null or empty string)
 * @param args The arguments to insert into this query
 * @throws SQLException If this query fails
 * @return the list of strings -> id mappings
 */
public static Map<String, Long> selectStringLongMap(Connection connection, String query, Object... args)
        throws SQLException {
    ArgumentNotValid.checkNotNull(connection, "Connection connection");
    ArgumentNotValid.checkNotNullOrEmpty(query, "String query");
    ArgumentNotValid.checkNotNull(args, "Object... args");
    PreparedStatement s = null;
    try {
        s = prepareStatement(connection, query, args);
        ResultSet result = s.executeQuery();
        Map<String, Long> results = new HashMap<String, Long>();
        while (result.next()) {
            String resultString = result.getString(1);
            long resultLong = result.getLong(2);
            if ((resultString == null) || (resultLong == 0L && result.wasNull())) {
                String warning = "NULL pointers found in entry (" + resultString + "," + resultLong
                        + ") in resultset from query: " + query;
                log.warn(warning);
            }
            results.put(resultString, resultLong);
        }
        return results;
    } finally {
        closeStatementIfOpen(s);
    }

}