user2500313
user2500313

Reputation: 39

How to retrive clob data from oracle collection

I have a requirment where oracle procedure is sending me a oracle collection. This collection contains clob data type.
How do I get this clob data ?

Code:

    public static void main(String[] args) throws SQLException {
            DBLayer db=new DBLayer();
            CallableStatement ftRPCaStmt = null;
            ResultSet requestPropCursor = null;
            CallableStatement callsmt=null;
            String dataCol="stg_core.tab_inft_flexi_gl_rec_hd2";
            Connection conn=db.getConnection();
    ArrayDescriptor structDescriptor1 = ArrayDescriptor.createDescriptor   (dataCol.toUpperCase(), conn);                   
                  ftRPCaStmt = conn.prepareCall("{ call stg_core.gl_test1_clob_c2(?,?,?) }");
            ftRPCaStmt.registerOutParameter(1, Types.VARCHAR);
            ftRPCaStmt.registerOutParameter(2, Types.VARCHAR);
            ftRPCaStmt.registerOutParameter(3, Types.ARRAY,dataCol.toUpperCase());
            ftRPCaStmt.execute();

            Object[] data = (Object[]) ((Array) ftRPCaStmt.getObject(3)).getArray();    

when I printed data I'm getting data value as Ljava.lang.Object;@b2fd8f, but I need the clob data..
Please suggest..

Upvotes: 0

Views: 538

Answers (1)

Jacob
Jacob

Reputation: 14731

Try as

callsmt.registerOutParameter(3, OracleTypes.CLOB);

and then

Clob  clob = proc_stmt.getClob(3);
Reader reader = clob .getCharacterStream();
            char[] buffer = new char[1];
            while(reader.read(buffer) > 0) {
                log.info(buffer);
            }           
//          log.info(retValue);
            .... 

the above code snippet is not compiled, this is to provide the guideline.

Upvotes: 1

Related Questions