Java SQL ResultSet Read wasNull(ResultSet rs, T value)

Here you can find the source of wasNull(ResultSet rs, T value)

Description

Convenient way to check if a JDBC-originated record was null.

License

Open Source License

Parameter

Parameter Description
rs The data source from which a value was read
value The value that was read

Return

The value or null if the is true

Declaration

public static final <T> T wasNull(ResultSet rs, T value) throws SQLException 

Method Source Code


//package com.java2s;

import java.sql.CallableStatement;

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

public class Main {
    /**/* w w  w  .ja  va  2s.co m*/
     * Convenient way to check if a JDBC-originated record was <code>null</code>.
     * <p>
     * This is useful to check if primitive types obtained from the JDBC API
     * were actually SQL NULL values.
     *
     * @param stream The data source from which a value was read
     * @param value The value that was read
     * @return The <code>value</code> or <code>null</code> if the
     *         {@link SQLInput#wasNull()} is <code>true</code>
     */
    public static final <T> T wasNull(SQLInput stream, T value) throws SQLException {
        return stream.wasNull() ? null : value;
    }

    /**
     * Convenient way to check if a JDBC-originated record was <code>null</code>.
     * <p>
     * This is useful to check if primitive types obtained from the JDBC API
     * were actually SQL NULL values.
     *
     * @param rs The data source from which a value was read
     * @param value The value that was read
     * @return The <code>value</code> or <code>null</code> if the
     *         {@link ResultSet#wasNull()} is <code>true</code>
     */
    public static final <T> T wasNull(ResultSet rs, T value) throws SQLException {
        return rs.wasNull() ? null : value;
    }

    /**
     * Convenient way to check if a JDBC-originated record was <code>null</code>.
     * <p>
     * This is useful to check if primitive types obtained from the JDBC API
     * were actually SQL NULL values.
     *
     * @param statement The data source from which a value was read
     * @param value The value that was read
     * @return The <code>value</code> or <code>null</code> if the
     *         {@link CallableStatement#wasNull()} is <code>true</code>
     */
    public static final <T> T wasNull(CallableStatement statement, T value) throws SQLException {
        return statement.wasNull() ? null : value;
    }
}

Related

  1. readBytes(ResultSet rs, int pos)
  2. readDate(ResultSet result, int index)
  3. readMap(final ResultSet rs)
  4. readObject(java.sql.ResultSet resultSet, int index)
  5. readResults(ResultSet resultSet)
  6. wasNull(ResultSet rs, T value)
  7. wasNull(ResultSet rs, T value)