Product Documentation

FairCom Java & .NET Stored Procedures

Previous Topic

Next Topic

SQLCursor.getValue

Returns the value of the specified field of the fetched row of a cursor or result set as a Java object. This returned object must be typecasted to an appropriate SQL type.

Format

public Object getValue(int field, short dType)

Returns

Returns the Object specified by the field value.

Parameters

field

An integer that specifies which field of the fetched record is of interest. getValue() retrieves the value in the currently-fetched record of the column denoted by field (1 denotes the first column of the result set, 2 denotes the second, and so on).

The value in the column denoted by field cannot be null, or FairCom DB SQL returns an error:

(error(-20144): Null value fetched.)

This means you must always check whether a value is null before attempting to assign a value in an SQL result set to a procedure variable or output parameter. The SQLCursor class provides the wasNULL() method for this purpose. See Section "SQLCursor.wasNULL" for details.

dType

The expected data type of the return Object being returned.

Throws

DhSQLException

Example


CREATE PROCEDURE test_nulls2()

RESULT (col1 INTEGER,

col2 INTEGER,

col3 INTEGER)

BEGIN

Integer pvar_int1 = new Integer(0);

Integer pvar_int2 = new Integer(0);

Integer pvar_int3 = new Integer(0);

SQLCursor select_t1 = new SQLCursor

( "SELECT c1, c2, c3 from t1" );

select_t1.open();

select_t1.fetch();

while ( select_t1.found() )

{

// Assign values from the current row of the SQL result set

// to the pvar_intx procedure variables. Must first check

// whether the values fetched are null: if they are, must set

// pvars explicitly to null.

if ((select_t1.wasNULL(1)) == true)

pvar_int1 = null;

else

pvar_int1 = (Integer)select_t1.getValue(1,INTEGER);

if ((select_t1.wasNULL(2)) == true)

pvar_int2 = null;

else

pvar_int2 = (Integer)select_t1.getValue(2,INTEGER);

if ((select_t1.wasNULL(3)) == true)

pvar_int3 = null;

else

pSQLResultSet.set(1,pvar_int1);

SQLResultSet.set(2,pvar_int2);

SQLResultSet.set(3,pvar_int3);

SQLResultSet.insert();

select_t1.fetch();

}

select_t1.close();

END

TOCIndex