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:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,null)");
    st.executeUpdate("insert into survey (id,name ) values (3,'Tom')");
    st = conn.createStatement();//from  w w  w. j a va2  s  .  c o  m
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    while (rs.next()) {
        String name = rs.getString(2);
        if (rs.wasNull()) {
            System.out.println("was NULL");
        } else {
            System.out.println("not NULL");
        }
    }

    rs.close();
    st.close();
    conn.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement();

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (10,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (null,null)");
    st = conn.createStatement();/*from  ww w  . ja v a  2 s  . co  m*/
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    while (rs.next()) {
        int id = rs.getInt(1);
        System.out.println(id);
        if (rs.wasNull()) {
            id = -1;
        }
        System.out.println(id);
    }
    rs.close();
    st.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,null)");
    st = conn.createStatement();//from   w ww.ja va  2s.c  o m
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    // extract data from the ResultSet
    while (rs.next()) {
        int id = rs.getInt(1);
        System.out.println("id=" + id);
        String name = rs.getString(2);
        System.out.println("name=" + name);
        if (rs.wasNull()) {
            System.out.println("name is null");
        } else {
            System.out.println("name is not null");
        }
        System.out.println("---------------");
    }
    rs.close();
    st.close();
    conn.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement();

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,null)");
    st = conn.createStatement();//  ww w  .  ja va2 s . c  om
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    // extract data from the ResultSet
    while (rs.next()) {
        int id = rs.getInt(1);
        System.out.println("id=" + id);
        String name = rs.getString(2);
        System.out.println("name=" + name);
        if (rs.wasNull()) {
            System.out.println("name is null");
        } else {
            System.out.println("name is not null");
        }
        System.out.println("---------------");
    }
    rs.close();
    st.close();
    conn.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement();

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,null)");
    st = conn.createStatement();/*from   ww  w .ja  v a  2s  .c o  m*/
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    // extract data from the ResultSet
    while (rs.next()) {
        int id = rs.getInt("id");
        System.out.println("id=" + id);
        String name = rs.getString(2);
        System.out.println("name=" + name);
        if (rs.wasNull()) {
            System.out.println("name is null");
        } else {
            System.out.println("name is not null");
        }
        System.out.println("---------------");
    }
    rs.close();
    st.close();
    conn.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String url = "jdbc:odbc:technical_library";
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String theStatement = "SELECT authid, lastname, firstname, email FROM authors ORDER BY authid";

    try {//from  w  w  w  .j a v  a2 s . com
        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, "guest", "guest");
        Statement queryAuthors = connection.createStatement();
        ResultSet results = queryAuthors.executeQuery(theStatement);

        String lastname, firstname, email;
        int id;
        while (results.next()) {
            id = results.getInt(1);
            lastname = results.getString(2);
            firstname = results.getString(3);
            email = results.getString(4);

            if (results.wasNull()) {
                email = "no email";
            }
            System.out.println(Integer.toString(id) + ", " + lastname.trim() + ", " + firstname.trim() + ", "
                    + email.trim());
        }
        queryAuthors.close();
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:org.spc.ofp.data.Repository.java

public static Integer readInteger(final ResultSet rs, final String columnName) throws SQLException {
    final int value = rs.getInt(columnName);
    return rs.wasNull() ? null : Integer.valueOf(value);
}

From source file:org.spc.ofp.data.Repository.java

public static Long readLong(final ResultSet rs, final String columnName) throws SQLException {
    final long value = rs.getLong(columnName);
    return rs.wasNull() ? null : Long.valueOf(value);
}

From source file:org.spc.ofp.data.Repository.java

public static Double readDouble(final ResultSet rs, final String columnName) throws SQLException {
    final double value = rs.getDouble(columnName);
    return rs.wasNull() ? null : Double.valueOf(value);
}

From source file:com.flexive.core.search.DataSelector.java

/**
 * Decode the binary value that was previously selected with
 * {@link #selectBinary(String)} at the given result set position.
 *
 * @param rs    the result set//from   w  w  w . j a v  a 2s  . c  om
 * @param pos   the column index
 * @return      the decoded binary
 * @throws SQLException on database errors
 */
public static BinaryDescriptor decodeBinary(ResultSet rs, int pos) throws SQLException {
    final String encodedBinary = rs.getString(pos);
    if (rs.wasNull()) {
        return new BinaryDescriptor();
    }
    final String[] values = StringUtils.split(encodedBinary, BINARY_DELIM);
    return new BinaryDescriptor(CacheAdmin.getStreamServers(),
            java.lang.Long.parseLong(getBinaryValue(values, "ID")), 1, 1,
            java.lang.Long.parseLong(getBinaryValue(values, "CREATED_AT")), getBinaryValue(values, "NAME"),
            java.lang.Long.parseLong(getBinaryValue(values, "BLOBSIZE")), null,
            getBinaryValue(values, "MIMETYPE"), "1".equals(getBinaryValue(values, "ISIMAGE")),
            Double.parseDouble(getBinaryValue(values, "RESOLUTION")),
            java.lang.Integer.parseInt(getBinaryValue(values, "WIDTH")),
            java.lang.Integer.parseInt(getBinaryValue(values, "HEIGHT")), getBinaryValue(values, "MD5SUM"));
}