0

i m getting the clob data from db2 and storing in an list and then writing to a text file,but jappnese characters are not getting encoded.

Getting data from db2

if (rs != null) {
                int slNo = 0;
                BufferedReader reader = null;
                int counter = 0;

                // Read the list of content next
                while (rs.next() && !rs.isClosed()) {
                    // Reserve the first entry in the
                    // result List for header column
                    if (counter == 0) {
                        resultList.add(null);
                        counter++;
                    }
                    reader = new BufferedReader(new InputStreamReader(rs.getAsciiStream(1)));

                    slNo = rs.getInt(2);

                    if (slNo == 1) {

                        resultList.set(0, reader.readLine());
                    } else {
                        // result data
                        resultList.add(reader.readLine());
                           }}}

Writing to file

 FileOutputStream outObjectOutputStream = null;
 try {
        outObjectOutputStream = new FileOutputStream(absoluteFilePath);

        for (String line : resultList) {
            if (line != null) {
                outObjectOutputStream.write(line.getBytes());
                outObjectOutputStream.write("\n".getBytes());
                    }}'

1 Answers1

0

You have to specify the character encoding that same as the one used in DB. If the table is a Unicode table, DB2 uses UTF-8 for CLOB.

If you have read the content of CLOB collectly (try System.out.println(line); before write the string to the stream), try writing the content with line.getBytes("UTF-8"); instead of line.getBytes();. See https://stackoverflow.com/a/12659462/3902663 for more information.

SATO Yusuke
  • 1,600
  • 15
  • 39