Search code examples
javaoraclejdbcstructclob

CLOB value turn into empty in java side


I want to get value of the column which data type is CLOB. In Java side I am getting attributes of the struct which are coming from the our procedure which called "get_val". attr[4] is empty althought procedure doesn't return empty. It works fine for some CLOB attrubites but sometimes returns empty property. I am sure that it comes empty because when I try to send length of attr[4]. It shows "0". But from procedure it shows 38 symbols.

What can be reason for this ? How I can fix it ?

public ValueEntity getAttributeValue(String token, Long objectId, Integer attrId, Date bankDate) throws SQLException, IOException{
    try{    
        createContext(token,true);

        ocstmt.close();

        ocstmt = (OracleCallableStatement) oracleConnection.prepareCall("{ ? = call package.get_val(?,?,?) }");
        ocstmt.registerOutParameter(1, OracleTypes.STRUCT, "T_VAL");
        setLong(2, objectId);
        setInt(3, attrId);
        setDate(4, bankDate);

        ocstmt.setQueryTimeout(200);

        ocstmt.execute();

        return DBUtil.ComplexTypeMapping.getValueEntity(oracleConnection, (Struct)ocstmt.getObject(1));
    }finally{
        releaseAllResources(false);
    }
}



   public static ValueEntity getValueEntity(OracleConnection connection, Struct struct) throws SQLException, IOException{
        if(struct == null) return null;
        Object[] attrs = struct.getAttributes();
        ValueEntity data = new ValueEntity();
        data.setType(bigdecimalAsInteger((BigDecimal)attrs[0]));
        data.setNum(bigdecimalAsDouble((BigDecimal)attrs[1]));
        data.setStr(attrs[2] != null?String.valueOf(attrs[2]):null);
        data.setDate((Date)attrs[3]);

        //Clob clobAttr= (Clob)attrs[4];
        //long clobLength= clobAttr.length();
        //data.setClob( String.valueOf(clobLength));
        data.setClob(getClobAsString((Clob)attrs[4]));


        data.setNumArr(getDoubleArray((Array)attrs[5]));
        data.setStrArr(getStringArray((Array)attrs[6]));
        data.setDateArr(getDateArray((Array)attrs[7]));
        return data;
    }

Solution

  • Finally I have found that problem was related with IBM websphere version.It was 10.0.0.3 but now we are using 10.0.0.9 version.