Porting oracle:thin to weblogic:oracle

Hi everyone!

Since pstmt.setAsciiSream or setBinaryStream doesn't seem to work for data larger than 4k while using oracle:thin I inserted Blobs or Clobs usually in the following way:

Clob myClob = (Clob)resultSet.getObject("text");

java.io.Writer CLOBout = ((oracle.sql.CLOB)myClob).getCharacterOutputStream();

CLOBout.write(text);

I had to port an application from Resin to Bea and had to switch to the Weblogic-Driver, and of course oracle.sql.CLOB doesn't exist there, so I tried again the 'simple' method using pstmt.setAsciiSream / pstmt.setBinaryStream.

To my surprise it even worked with data>4k, while it still produced errors using Resin/Oracle:thin. Does anyone know the reason for that? Or does anyone have a working solution to write Clobs/Blobs for both drivers (Reading is no problem)?

[896 byte] By [HaPe] at [2007-9-26 1:22:33]
# 1
Hi,Why don't you use weblogic.jdbc.common.OracleClob instead?Also take a look at the example located in %BEA_HOME%\wlserver6.0\samples\examples\jdbc\oracleHope this helps,Kurt.
leukbr at 2007-6-29 0:59:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Yes, that would be possible. But I'd like to have the same code run on both Resin with Oracle:thin and Weblogic with the Weblogic driver ;-)

This could be a solution:

Clob myClob = (Clob)result.getObject("clob")

Class[] argtypes = new Class[]{};

java.lang.reflect.Method myClobMethod = myClob.getDeclaredMethod("getCharacterOutputStream",argtypes)

// I am not sure if args simply can be null since getCharacterOutputStream doesn't take any parameters

Object[] args = new Object[]{};

java.io.Writer CLOBout = myClobMethod.invoke(myobject,args);

I can't try until monday though, and (assuming it works) I wonder how performant it will be ;-)

HaPe at 2007-6-29 0:59:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Sorry, of course it should read:

Clob myClob = (Clob)result.getObject("clob");

Class[] argtypes = new Class[]{};

java.lang.reflect.Method myClobMethod = myClob.getDeclaredMethod("getCharacterOutputStream",argtypes)

// I am not sure if args simply can be null since getCharacterOutputStream doesn't take any parameters

Object[] args = new Object[]{};

java.io.Writer CLOBout = myClobMethod.invoke(myClob,args);

HaPe at 2007-6-29 0:59:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

That's how it worked (in case anyone cares :-)):

private static java.lang.reflect.Method myBlobMethod;

// ...

Blob myBlob= (Blob)rs.getObject("IMAGE_DATA");

if (myBlobMethod==null) {

myBlobMethod = (myBlob.getClass()).getDeclaredMethod("getBinaryOutputStream",null);

}

java.io.OutputStream BLOBout= (java.io.OutputStream)myBlobMethod.invoke(myBlob,null);

HaPe at 2007-6-29 0:59:48 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...