繁体   English   中英

来自 Db2 数据库的日语字符编码 in-java-

[英]japanese-character-encoding-in-java- from Db2 database

我从 db2 获取 clob 数据并存储在列表中,然后写入文本文件,但日语字符没有被编码。

从 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());
                           }}}

写入文件

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

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

您必须指定与 DB 中使用的字符编码相同的字符编码。 如果表是 Unicode 表,则 DB2 对 CLOB 使用 UTF-8。

如果您已集体读取 CLOB 的内容(尝试System.out.println(line);在将字符串写入流之前),请尝试使用line.getBytes("UTF-8");写入内容而不是line.getBytes(); . 有关详细信息,请参阅https://stackoverflow.com/a/12659462/3902663

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM