Java Code Examples for java.sql.ResultSet.wasNull()

The following are Jave code examples for showing how to use wasNull() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ChronoBike   File: RecordColTypeManagerDecimalLong.java   View Source Code Vote up 7 votes
boolean fillColValue(ResultSet rs, VarBase varInto)
{
	try
	{		
		long lValue = rs.getLong(m_nColSourceIndex);
		if (lValue != 0 || !rs.wasNull())
		{
			varInto.m_varDef.write(varInto.m_bufferPos, lValue);
			return false;
		}
	}
	catch (SQLException e)
	{
		LogSQLException.log(e);
		// Maybe should I set m_bNull = true; ?
	}
	varInto.m_varDef.write(varInto.m_bufferPos, 0);
	return true;
}
 
Example 2
Project: uroborosql   File: OptionalIntPropertyMapper.java   View Source Code Vote up 6 votes
@Override
public OptionalInt getValue(final JavaType type, final ResultSet rs, final int columnIndex,
		final PropertyMapperManager mapperManager) throws SQLException {
	int value = rs.getInt(columnIndex);
	if (!rs.wasNull()) {
		return OptionalInt.of(value);
	} else {
		return OptionalInt.empty();
	}
}
 
Example 3
Project: graphium   File: RoadDamageRowMapper.java   View Source Code Vote up 6 votes
@Override
public IBaseSegment mapRow(ResultSet rs, int rowNum) throws SQLException {
	RoadDamageImpl rd = new RoadDamageImpl();
	boolean valid = false;
	try {
		ColumnFinder colFinder = new ColumnFinder(rs);

		if (colFinder.getColumnIndex(QUERY_PREFIX + "_segment_id") > -1) {
			rd.setSegmentId(rs.getLong(QUERY_PREFIX + "_segment_id"));
			if (!rs.wasNull()) {
				valid = true;
			}
		}
		if (colFinder.getColumnIndex(QUERY_PREFIX + "_direction_tow") > -1) {
			rd.setDirectionTow(rs.getBoolean(QUERY_PREFIX + "_direction_tow"));
		}
		if (colFinder.getColumnIndex(QUERY_PREFIX + "_graphversion_id") > -1) {
			rd.setGraphVersionId(rs.getLong(QUERY_PREFIX + "_graphversion_id"));
		}
		if (colFinder.getColumnIndex(QUERY_PREFIX + "_start_offset") > -1) {
			rd.setStartOffset((float)rs.getDouble(QUERY_PREFIX + "_start_offset"));
		}
		if (colFinder.getColumnIndex(QUERY_PREFIX + "_end_offset") > -1) {
			rd.setEndOffset((float)rs.getDouble(QUERY_PREFIX + "_end_offset"));
		}
		if (colFinder.getColumnIndex(QUERY_PREFIX + "_type") > -1) {
			rd.setType(rs.getString(QUERY_PREFIX + "_type"));
		}
	} catch (SQLException e) {}

	if (valid) {
		IBaseSegment segment = new BaseSegment();
		segment.setId(rd.getSegmentId());
		segment.addXInfo(rd);
		return segment;
	} else {
		return null;
	}
}
 
Example 4
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 6 votes
public Object getResult(ResultSet rs, String columnName) throws SQLException {

            Object sqlTime = rs.getTime(columnName);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return sqlTime;
            }
        }
 
Example 5
Project: ChronoBike   File: RecordColTypeManagerDecimalInt.java   View Source Code Vote up 6 votes
public boolean transfer(int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert)
{
	try
	{
		int nValue = resultSetSource.getInt(m_nColSourceIndex);
		if (!resultSetSource.wasNull())
			insertStatementInsert.setInt(m_nColSourceIndex, nValue);
		else
			insertStatementInsert.setNull(m_nColSourceIndex, Types.INTEGER);
		return true;
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	return false;		
}
 
Example 6
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, String columnName) throws SQLException {

            long l = rs.getLong(columnName);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return new Long(l);
            }
        }
 
Example 7
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {

            Object bigdec = rs.getBigDecimal(columnIndex);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return bigdec;
            }
        }
 
Example 8
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {

            Object sqlDate = rs.getDate(columnIndex);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return sqlDate;
            }
        }
 
Example 9
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, String columnName) throws SQLException {

            Object obj = rs.getObject(columnName);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return obj;
            }
        }
 
Example 10
Project: parabuild-ci   File: TestSql.java   View Source Code Vote up 5 votes
/**
 * In 1.8.0.2, this fails in client / server due to column type of the
 * second select for b1 being boolean, while the first select is interpreted
 * as varchar. The rowOutputBase class attempts to cast the Java Boolean
 * into String.
 */
public void testUnionColumnTypes() {

    try {
        Connection conn = newConnection();
        Statement  stmt = conn.createStatement();

        stmt.execute("DROP TABLE test1 IF EXISTS");
        stmt.execute("DROP TABLE test2 IF EXISTS");
        stmt.execute("CREATE TABLE test1 (id int, b1 boolean)");
        stmt.execute("CREATE TABLE test2 (id int)");
        stmt.execute("INSERT INTO test1 VALUES(1,true)");
        stmt.execute("INSERT INTO test2 VALUES(2)");

        ResultSet rs = stmt.executeQuery(
            "select id,null as b1 from test2 union select id, b1 from test1");
        Boolean[] array = new Boolean[2];

        for (int i = 0; rs.next(); i++) {
            boolean boole = rs.getBoolean(2);

            array[i] = Boolean.valueOf(boole);

            if (rs.wasNull()) {
                array[i] = null;
            }
        }

        boolean result = (array[0] == null && array[1] == Boolean.TRUE)
                         || (array[0] == Boolean.TRUE
                             && array[1] == null);

        assertTrue(result);
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("TestSql.testUnionColumnType() error: "
                           + e.getMessage());
    }
}
 
Example 11
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {

            short s = rs.getShort(columnIndex);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return new Short(s);
            }
        }
 
Example 12
Project: react-native-mssql   File: JSON.java   View Source Code Vote up 4 votes
public static JSONArray toJSON(ResultSet rs) throws SQLException, JSONException {
    JSONArray json = new JSONArray();
    ResultSetMetaData rsmd = rs.getMetaData();
    int numColumns = rsmd.getColumnCount();
    String column_name;

    while (rs.next()) {
        JSONObject obj = new JSONObject();

        for (int i = 1; i < numColumns + 1; i++) {
            column_name = rsmd.getColumnName(i);
            String myValue = rs.getString(i);
            if (!rs.wasNull()) {
                if (rsmd.getColumnType(i) == java.sql.Types.CHAR) {
                    obj.put(column_name, rs.getString(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) {
                    obj.put(column_name, rs.getString(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.LONGVARCHAR) {
                    obj.put(column_name, rs.getString(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BINARY) {
                    obj.put(column_name, rs.getBytes(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.VARBINARY) {
                    obj.put(column_name, rs.getBytes(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.LONGVARBINARY) {
                    obj.put(column_name, rs.getBinaryStream(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BIT) {
                    obj.put(column_name, rs.getBoolean(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
                    obj.put(column_name, rs.getInt(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
                    obj.put(column_name, rs.getInt(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) {
                    obj.put(column_name, rs.getInt(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
                    obj.put(column_name, rs.getInt(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.REAL) {
                    obj.put(column_name, rs.getFloat(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
                    obj.put(column_name, rs.getDouble(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
                    obj.put(column_name, rs.getFloat(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.DECIMAL) {
                    obj.put(column_name, rs.getBigDecimal(i).doubleValue());
                } else if (rsmd.getColumnType(i) == java.sql.Types.NUMERIC) {
                    obj.put(column_name, rs.getBigDecimal(i).doubleValue());
                } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
                    obj.put(column_name, rs.getDate(i).toString());
                } else if (rsmd.getColumnType(i) == java.sql.Types.TIME) {
                    obj.put(column_name, rs.getDate(i).toString());
                } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
                    obj.put(column_name, rs.getTimestamp(i).toString());
                } else if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
                    obj.put(column_name, rs.getArray(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
                    obj.put(column_name, rs.getBoolean(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) {
                    obj.put(column_name, rs.getBlob(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
                    obj.put(column_name, rs.getNString(i));
                } else {
                    obj.put(column_name, rs.getObject(i));
                }
            } else {
                obj.put(column_name, JSONObject.NULL);
            }
        }
        json.put(obj);
    }
    return json;
}
 
Example 13
Project: QDrill   File: DatabaseMetaDataGetColumnsTest.java   View Source Code Vote up 4 votes
private Integer getIntOrNull( ResultSet row, String columnName ) throws SQLException {
  final int value = row.getInt( columnName );
  return row.wasNull() ? null : new Integer( value );
}
 
Example 14
Project: burstcoin   File: TransactionDb.java   View Source Code Vote up 4 votes
static TransactionImpl loadTransaction(Connection con, ResultSet rs) throws NxtException.ValidationException {
    try {

        byte type = rs.getByte("type");
        byte subtype = rs.getByte("subtype");
        int timestamp = rs.getInt("timestamp");
        short deadline = rs.getShort("deadline");
        byte[] senderPublicKey = rs.getBytes("sender_public_key");
        long amountNQT = rs.getLong("amount");
        long feeNQT = rs.getLong("fee");
        byte[] referencedTransactionFullHash = rs.getBytes("referenced_transaction_full_hash");
        int ecBlockHeight = rs.getInt("ec_block_height");
        long ecBlockId = rs.getLong("ec_block_id");
        byte[] signature = rs.getBytes("signature");
        long blockId = rs.getLong("block_id");
        int height = rs.getInt("height");
        long id = rs.getLong("id");
        long senderId = rs.getLong("sender_id");
        byte[] attachmentBytes = rs.getBytes("attachment_bytes");
        int blockTimestamp = rs.getInt("block_timestamp");
        byte[] fullHash = rs.getBytes("full_hash");
        byte version = rs.getByte("version");

        ByteBuffer buffer = null;
        if (attachmentBytes != null) {
            buffer = ByteBuffer.wrap(attachmentBytes);
            buffer.order(ByteOrder.LITTLE_ENDIAN);
        }

        TransactionType transactionType = TransactionType.findTransactionType(type, subtype);
        TransactionImpl.BuilderImpl builder = new TransactionImpl.BuilderImpl(version, senderPublicKey,
                amountNQT, feeNQT, timestamp, deadline,
                transactionType.parseAttachment(buffer, version))
                .referencedTransactionFullHash(referencedTransactionFullHash)
                .signature(signature)
                .blockId(blockId)
                .height(height)
                .id(id)
                .senderId(senderId)
                .blockTimestamp(blockTimestamp)
                .fullHash(fullHash);
        if (transactionType.hasRecipient()) {
            long recipientId = rs.getLong("recipient_id");
            if (! rs.wasNull()) {
                builder.recipientId(recipientId);
            }
        }
        if (rs.getBoolean("has_message")) {
            builder.message(new Appendix.Message(buffer, version));
        }
        if (rs.getBoolean("has_encrypted_message")) {
            builder.encryptedMessage(new Appendix.EncryptedMessage(buffer, version));
        }
        if (rs.getBoolean("has_public_key_announcement")) {
            builder.publicKeyAnnouncement(new Appendix.PublicKeyAnnouncement(buffer, version));
        }
        if (rs.getBoolean("has_encrypttoself_message")) {
            builder.encryptToSelfMessage(new Appendix.EncryptToSelfMessage(buffer, version));
        }
        if (version > 0) {
            builder.ecBlockHeight(ecBlockHeight);
            builder.ecBlockId(ecBlockId);
        }

        return builder.build();

    } catch (SQLException e) {
        throw new RuntimeException(e.toString(), e);
    }
}
 
Example 15
Project: typehandlers-threeten-extra   File: HoursTypeHandler.java   View Source Code Vote up 4 votes
@Override
public Hours getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
  int hours = rs.getInt(columnIndex);
  return rs.wasNull() ? null : Hours.of(hours);
}
 
Example 16
Project: typehandlers-threeten-extra   File: YearsTypeHandler.java   View Source Code Vote up 4 votes
@Override
public Years getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
  int years = rs.getInt(columnIndex);
  return rs.wasNull() ? null : Years.of(years);
}
 
Example 17
Project: typehandlers-threeten-extra   File: SecondsTypeHandler.java   View Source Code Vote up 4 votes
@Override
public Seconds getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
  int seconds = rs.getInt(columnIndex);
  return rs.wasNull() ? null : Seconds.of(seconds);
}
 
Example 18
Project: jaffa-framework   File: TypeDefs.java   View Source Code Vote up 3 votes
/** Gets a parameter from the ResultSet.
 * @return the parameter.
 * @param engineType The engine type as defined in init.xml
 * @param rs The ResultSet.
 * @param columnName The name of the parameter.
 * @throws SQLException if a database access error occurs.
 * @throws IOException if any error occurs in reading the data from the database.
 */
public Object getAppObject(ResultSet rs, String columnName, String engineType) throws SQLException, IOException {
    long value = rs.getLong(columnName);
    if (rs.wasNull())
        return null;
    else
        return new Long(value);
}
 
Example 19
Project: jaffa-framework   File: TypeDefs.java   View Source Code Vote up 3 votes
/** Gets a parameter from the ResultSet.
 * @return the parameter.
 * @param engineType The engine type as defined in init.xml
 * @param rs The ResultSet.
 * @param columnName The name of the parameter.
 * @throws SQLException if a database access error occurs.
 * @throws IOException if any error occurs in reading the data from the database.
 */
public Object getAppObject(ResultSet rs, String columnName, String engineType) throws SQLException, IOException {
    boolean value = rs.getBoolean(columnName);
    if (rs.wasNull())
        return null;
    else
        return new Boolean(value);
}
 
Example 20
Project: morpheus-core   File: SQLExtractor.java   View Source Code Vote up 2 votes
/**
 * Returns the value from the result set at current row and col index specified
 * @param rs        the result set reference
 * @param colIndex  the result set column index
 * @return          the value extracted from result set
 * @throws SQLException
 */
public double getDouble(ResultSet rs, int colIndex) throws SQLException {
    final double value = rs.getDouble(colIndex);
    return rs.wasNull() ? Double.NaN : value;
}