General J2EE: Java CharacterSet Problem

  1. Java CharacterSet Problem (3 messages)

    Dear All:
      I meet some Chinese CharacterSet Problem,the following are the problem description.If anyone have some solution in the java code.Please inform me.Thank you.

    1.Development Environment:
      Tomcat 4.04
      JDK 1.3.1-03
      Oracle 8.1.6

    2.Oracle DB CharacterSet Setting:


    3.Query Result Binary Code(Chinese is Correct):

    Typ=1 Len=8 CharacterSet=ZHT16DBT: b1,4d,ae,d7,a6,fe,aa,f7
    Typ=1 Len=8 CharacterSet=ZHT16DBT: 44,41,54,41,a6,fe,aa,f7
    Typ=1 Len=8 CharacterSet=ZHT16DBT: aa,bd,be,50,a6,fe,aa,f7
    Typ=1 Len=8 CharacterSet=ZHT16DBT: a8,e4,a5,a6,a6,fe,aa,f7
    Typ=1 Len=14 CharacterSet=ZHT16DBT: b6,7d,b3,71,a6,fe,aa,f7,28,b8,67,be,50,29
    Typ=1 Len=6 CharacterSet=ZHT16DBT: a9,e8,a5,ce,a8,e9
    Typ=1 Len=21 CharacterSet=ZHT16DBT: 49,4d,4f,44,45,b1,c0,bc,73,bc,fa,aa,f7,28,b7
    Typ=1 Len=13 CharacterSet=ZHT16DBT: 49,4d,4f,44,45,32,30,30,30,a7,e9,c5,fd
    Typ=1 Len=21 CharacterSet=ZHT16DBT: 49,4d,4f,44,45,b1,c0,bc,73,bc,fa,aa,f7,28,c2
    Typ=1 Len=14 CharacterSet=ZHT16DBT: b6,7d,b3,71,a6,fe,aa,f7,28,aa,bd,be,50,29
    Typ=1 Len=17 CharacterSet=ZHT16DBT: 61,69,72,74,69,6d,65,a6,fe,aa,f7,28,aa,bd,be
    Typ=1 Len=9 CharacterSet=ZHT16DBT: 73,69,6d,a5,64,a7,e9,c5,fd
    Typ=1 Len=10 CharacterSet=ZHT16DBT: a6,a9,b8,c9,a6,fe,a6,fe,aa,f7
    Typ=1 Len=8 CharacterSet=ZHT16DBT: af,53,a7,4f,bc,fa,aa,f7
    Typ=1 Len=17 CharacterSet=ZHT16DBT: 61,69,72,74,69,6d,65,a6,fe,aa,f7,28,b8,67,be
    Typ=1 Len=12 CharacterSet=ZHT16DBT: b5,4c,ac,f9,a4,57,bd,75,a6,fe,aa,f7
    Typ=1 Len=10 CharacterSet=ZHT16DBT: c0,78,ad,c8,a5,64,bc,fa,aa,f7
    Typ=1 Len=16 CharacterSet=ZHT16DBT: a4,e2,be,f7,a5,58,b3,66,ab,e1,b0,68,bc,fa,c0
    Typ=1 Len=12 CharacterSet=ZHT16DBT: a5,5b,b7,f9,aa,41,b0,c8,a6,fe,aa,f7
    Typ=1 Len=17 CharacterSet=ZHT16DBT: a5,5b,b7,f9,52,45,54,45,4e,54,49,4f,4e,a6,fe
    Typ=1 Len=12 CharacterSet=ZHT16DBT: b9,77,a5,fd,b6,7d,a9,f1,c3,42,ab,d7
    Typ=1 Len=4 CharacterSet=ZHT16DBT: a4,eb,a5,49
    Typ=1 Len=6 CharacterSet=ZHT16DBT: b4,ab,b8,c9,a5,64
    Typ=1 Len=4 CharacterSet=ZHT16DBT: b4,ab,b8,b9
    Typ=1 Len=8 CharacterSet=ZHT16DBT: a5,4e,a6,ac,b8,dc,b6,4f
    Typ=1 Len=8 CharacterSet=ZHT16DBT: a6,db,b0,ca,c2,e0,b1,62
    Typ=1 Len=13 CharacterSet=ZHT16DBT: 52,65,74,65,6e,74,69,6f,6e,aa,41,b0,c8
    Typ=1 Len=7 CharacterSet=ZHT16DBT: 54,45,53,54,20,a5,ce
    Typ=1 Len=4 CharacterSet=ZHT16DBT: 48,47,48,47

    4.Java Code:

    import java.util.*;
    import java.sql.*;
    public class Test {
      public static void main(String[] args) {
        String dbDriver = "oracle.jdbc.driver.OracleDriver";
        String dbUrl = "";
        String user = "";
        String password = "";
    // String SQLString = "select DUMP(DES, 1016) from COMM_TYPE_LOOKUP";
        String SQLString = "select DES from COMM_TYPE_LOOKUP";
        try {
          Properties pro = new Properties();
          pro.put("user", user);
          pro.put("password", password);
          pro.put("charSet", "Big5");
          Connection c = DriverManager.getConnection(dbUrl, pro);
          Statement s = c.createStatement();
          ResultSet r = s.executeQuery(SQLString); // SQL code:
          while(r.next()) {
            System.out.println(new String(r.getBytes(1), "Big5"));
        } catch(Exception e) {

    5.Wrong Result:







    Threaded Messages (3)

  2. Java CharacterSet Problem[ Go to top ]


      I guess your problem is solely on oracle side and not on java side. As you know java supports UTF/Unicode character format and hence chinese is anyway covered under it. what you might be having problem at is when u persist the information in oracle db and try to recover it. In oracle you have option of setting char set to some perticular char set. and this has to put put in right way to get the desired results.

     Talk to your DBA and he will give you list of char sets supported by oracle, my best hunch will be to set oracle char set which supports UTF and unicode char sets and you problem will be solved

  3. Reply[ Go to top ]

    Thanks Chetan!To change Oracle Server's CharacterSet is the last solution because there are over 10 million records in this DB.If change the db Setting,it should make big change in the DB.But many other system use this DB at the same time.I wish no change in the Oracle CharacterSet Configuration.So, do you have any other solution in the java code?

  4. Java CharacterSet Problem[ Go to top ]


       Try reading your data from ResultSet in binary format. later typecaste it to String, this is a hunch for getting final results. (Assuming that when oracle is storing the data itz not truncating it and just interpresting it in wrong way).

    This might work.

    The scenaro might be like this

    Your binary input for chinese single char: 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0
    Oracle interprete this char with 8 bits : 0 1 1 1 1 0 0 0 - char 1
                                                0 0 1 1 1 1 1 0 - char 2

    When you read the char Oracle returns char 1 with 8 0's prefixed for MSB side.

    hence if u read oracle output in full finary and later typecast it to string it will get in Unicode is my guess ...

    hope this helps