input stream to CLOB using java service

I have used the following code in java service to write input stream to CLOB.

CLOB clob = null;;
Writer out = clob.getCharacterOutputStream();
out.write( stream);

As the above code was not compiled ,I tried with one solution suggested by reamon in previous thread Writer out = clob.getAsciiOutputStream(); and got the same result.

Anyone has suggestion to write stream to CLOB?

Is the error that the compilation fails? Or that the code does not work?

CLOB clob = null;;

If this is the code in your service, you’re going to get a null pointer exception. clob is null so will fail.

You need to instantiate a clob object. The other thread you referenced shows how to get one by reading a record from the DB.

Thanks Reamon, It was compilation error pointing out.write() method.
Even after null assignment removed, it is giving compilation error

Can you post all the code to the service (I’m assuming the above is just a snippet)? Can you post the compiler error too?

out.write( stream); has two problems.

  1. The type declaration of isn’t legal here unless you are trying to cast the stream object. In that case the right syntax would be
    out.write(( stream);

  2. The stream object isn’t defined anywhere (I was assuming you posted just a snippet and omitted pipeline related code but perhaps that is not the case?).

Removing the null assignment didn’t really change anything. Variables without an initial assignment are null. At run-time the code will still fail if you don’t create/get a CLOB object. It will compile but it won’t run.

Reamon, you are right. It is just snippet and complete code which I used is given below.

IDataCursor idcPipeline = pipeline.getCursor();

String dbServer = null;
String dbUserId = null;
String dbPasswd = null;
String dbName = null;
String dbPort = null;
String proName = null;
String xmldata = null;
String table_name = null;
InputStream stream = null;
boolean cat_flag = true;
CLOB clob = null;

if (idcPipeline.first(“stream”))
stream = (InputStream)idcPipeline.getValue();
{ throw new ServiceException("No Input ‘stream’ ");

conn=getConnection123(dbServer , dbUserId, dbPasswd ,dbPort,dbName);

clob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);;
Writer out = clob.getCharacterOutputStream();
catch(Exception e)
throw new ServiceException(“Error occured”);


and the following compilation error is found with the above code.

[FONT=Times New Roman][SIZE=3]…/IntegrationServer/packages/myTest /code/source/test/ :424: cannot find symbol
symbol : method write(
location: class
…/IntegrationServer/packages/myTest /code/source/test/ uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

From the error message I understand that the method write() is used incorrectly. [/size][/font]

Sorry I missed this earlier. does not have a write() method. You’ll need create a loop that reads from the input stream and writes to the output stream.