cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "roy huang" <lingererhu...@hotmail.com>
Subject SQLTransformer get CLOB data wrong.
Date Fri, 28 May 2004 02:34:39 GMT
Hi,all:
    In SQLTransformer using such code to get current string from CLOB:
    InputStream inputStream = clob.getAsciiStream();
    byte[] readByte = new byte[numberOfChar];
    StringBuffer buffer = new StringBuffer();
    try {
     while(inputStream.read(readByte) > -1) {
      String string = new String(readByte, clobEncoding);
      buffer.append(string);
     }
    } catch(java.io.IOException ioException) {
     throw new SQLException("Error reading stream from CLOB");
    }
    retval = buffer.toString();

    clobEncoding is set by parameter clob-encoding

    But when I use oracle 9i(8i) NCLOB or CLOB to store Chinese string,this code doesn't work
though I try many encoding.I think the key is clob.getAsciiStream().I don't know the problem
is the jdbc driver's or getAsciiStream just can't deal with double bytes encoding.This code
works for me when using oracle NCLOB:
        Reader bodyReader = null;
    try {
     bodyReader = rs.getCharacterStream(i);
     if (bodyReader == null) {
      return null;
     }
     char [] buf = new char[256];
     int len;
     StringWriter out = new StringWriter(256);
     while ((len = bodyReader.read(buf)) >= 0) {
      out.write(buf, 0, len);
     }
     
     retval = out.toString();
     out.close();
    }
    catch (Exception e) {
     e.printStackTrace();
     throw new SQLException("Failed to load text field");
    }
    finally {
     try { bodyReader.close(); }
     catch(Exception e) { }
    }
    I don't know if this will help to make SQLTransformer get CLOB more portable.

Roy Huang
Mime
View raw message