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:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {//from  ww w.  j  a  va 2s  . c om
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFCrmDb2LUWSchema.class, "getNullableInt64", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWSchema.java

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

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlSchema.java

public static Integer getNullableInt32(ResultSet reader, int colidx) {
    try {/*  w  w w . ja  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(CFAstMySqlSchema.class, "getNullableInt32", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlSchema.java

public static Integer getNullableUInt16(ResultSet reader, int colidx) {
    try {//from www.  jav a  2s  .  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(CFAstMySqlSchema.class, "getNullableUInt16", e);
    }
}

From source file:com.splicemachine.derby.impl.load.HdfsUnsafeImportIT.java

public void helpTestConstraints(long maxBadRecords, int insertRowsExpected, boolean expectException)
        throws Exception {
    String tableName = "CONSTRAINED_TABLE";
    TableDAO td = new TableDAO(methodWatcher.getOrCreateConnection());
    td.drop(spliceSchemaWatcher.schemaName, tableName);

    methodWatcher.getOrCreateConnection().createStatement()
            .executeUpdate(format("create table %s ", spliceSchemaWatcher.schemaName + "." + tableName)
                    + "(EMPNO CHAR(6) NOT NULL CONSTRAINT EMP_PK PRIMARY KEY, "
                    + "SALARY DECIMAL(9,2) CONSTRAINT SAL_CK CHECK (SALARY >= 10000), "
                    + "BONUS DECIMAL(9,2),TAX DECIMAL(9,2),CONSTRAINT BONUS_CK CHECK (BONUS > TAX))");

    PreparedStatement ps = methodWatcher
            .prepareStatement(format("call SYSCS_UTIL.IMPORT_DATA_UNSAFE(" + "'%s'," + // schema name
                    "'%s'," + // table name
                    "'%s'," + // insert column list
                    "'%s'," + // file path
                    "','," + // column delimiter
                    "null," + // character delimiter
                    "null," + // timestamp format
                    "null," + // date format
                    "null," + // time format
                    "%d," + // max bad records
                    "'%s'," + // bad record dir
                    "null," + // has one line records
                    "null)", // char set
                    spliceSchemaWatcher.schemaName, tableName, "EMPNO,SALARY,BONUS,TAX",
                    getResourceDirectory() + "test_data/salary_check_constraint.csv", maxBadRecords,
                    BADDIR.getCanonicalPath()));

    try {//from  www .jav  a 2  s  .com
        ps.execute();
    } catch (SQLException e) {
        if (!expectException) {
            throw e;
        }
    }
    ResultSet rs = methodWatcher
            .executeQuery(format("select * from %s.%s", spliceSchemaWatcher.schemaName, tableName));
    List<String> results = Lists.newArrayList();
    while (rs.next()) {
        String name = rs.getString(1);
        String title = rs.getString(2);
        int age = rs.getInt(3);
        Assert.assertTrue("age was null!", !rs.wasNull());
        assertNotNull("Name is null!", name);
        assertNotNull("Title is null!", title);
        assertNotNull("Age is null!", age);
        results.add(String.format("name:%s,title:%s,age:%d", name, title, age));
    }
    Assert.assertEquals(format("Expected %s row1 imported", insertRowsExpected), insertRowsExpected,
            results.size());

    boolean exists = existsBadFile(BADDIR, "salary_check_constraint.csv.bad");
    String badFile = getBadFile(BADDIR, "salary_check_constraint.csv.bad");
    assertTrue("Bad file " + badFile + " does not exist.", exists);
    List<String> badLines = Files.readAllLines((new File(BADDIR, badFile)).toPath(), Charset.defaultCharset());
    assertEquals("Expected 2 lines in bad file " + badFile, 2, badLines.size());
    assertContains(badLines, containsString("BONUS_CK"));
    assertContains(badLines, containsString(spliceSchemaWatcher.schemaName + "." + tableName));
    assertContains(badLines, containsString("SAL_CK"));
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWSchema.java

public static BigDecimal getNullableUInt64(ResultSet reader, int colidx) {
    try {//www.  j  ava2  s.co m
        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(CFCrmDb2LUWSchema.class, "getNullableUInt64",
                e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlSchema.java

public static Long getNullableUInt32(ResultSet reader, int colidx) {
    try {/* ww  w.  j a  v  a 2 s  .  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(CFAstMySqlSchema.class, "getNullableUInt32", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlSchema.java

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

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlSchema.java

public static Short getNullableInt16(ResultSet reader, int colidx) {
    try {//from  w  w  w .j  a va 2 s .  co m
        short val = reader.getShort(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (new Short(val));
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAstMySqlSchema.class, "getNullableInt64", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlSchema.java

public static String getNullableString(ResultSet reader, int colidx) {
    try {/*from www .j  ava 2  s.  c o  m*/
        String val = reader.getString(colidx);
        if (reader.wasNull()) {
            return (null);
        } else {
            return (val);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(CFAstMySqlSchema.class, "getNullableString", e);
    }
}