Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4215746

sun.jdbc.odbc.JdbcOdbcObject.CharsToBytes lose converted bytes for Japanese

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.2_005
    • 1.2.0, 1.2.2
    • core-libs
    • 005
    • generic, x86
    • generic, windows_nt
    • Verified



        Name: clC74495 Date: 02/27/99


        1. We can't use SQL statement that contains Japanese characters,
        Because jdbc.odbc.JdbcOdbcObject.CharsToBytes loses converted
        bytes for Japanese.

         1a) Convert Japanese (MS932) char-array to byte-array by
              jdbc.odbc.JdbcOdbcObject.CharsToBytes.
         1b) On the output (byte-array), we'll lose trailing few bytes that
             depends on number of Double Byte Characters in input (char-array).

        2. Following is test program.

        === cut from here ===
        // foo.java

        import java.io.*;
        import sun.jdbc.odbc.*;

        public class foo {

          private static void dump(byte bytes[]) {
            char hex[] = {
              '0', '1', '2', '3', '4', '5', '6', '7',
              '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
            };
            for (int i = 0; i < bytes.length; ++i) {
              if ((i & 0xf) == 0) {
                System.out.println();
              }
              int hi = (((int) bytes[i]) >> 4) & 0xf;
              int lo = ((int) bytes[i]) & 0xf;
              System.out.print(" " + hex[hi] + hex[lo]);
            }
            System.out.println();
          }

          public static void main(String args[]) {
            String string = "select \u30d5\u30a3\u30fc\u30eb\u30c92 from Num12345";
            char chars[] = string.toCharArray();
            JdbcOdbcObject jdbcOdbcObject = new JdbcOdbcObject();
            try {
              byte bytes[];
              bytes = jdbcOdbcObject.CharsToBytes("MS932", chars);
              dump(bytes);
            } catch (UnsupportedEncodingException e) {
              System.err.println("UnsupportedEncodingException = " + e);
              System.exit(1);
            }
            System.exit(0);
          }
        }
        === end of cut ===

        3. We'll lose trailing 4 bytes on execution of foo.class.

        === actual result of foo.class ===

         73 65 6c 65 63 74 20 83 74 83 42 81 5b 83 8b 83
         68 32 20 66 72 6f 6d 20 4e 75 6d 31
        === end of result ===

        === expected result of foo.class ===

         73 65 6c 65 63 74 20 83 74 83 42 81 5b 83 8b 83
         68 32 20 66 72 6f 6d 20 4e 75 6d 31 32 33 34 35
        === end of result ===

        4. Nothing.

        5. I used MS932 as test case of encoding. But the problem will occurr on any Double Byte Character encodings.
        (Review ID: 54766)
        ======================================================================

              jellissunw Jon Ellis (Inactive)
              clucasius Carlos Lucasius (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: