2 Replies Latest reply: Jun 8, 2012 5:55 PM by DrClap RSS

    Display Unicode value in JTextField

    886265
      Hi,

      I have a column in oracle table having data type as NCHAR, and carrying value in UNICode (i.e. its a person name in urdu language).

      Right now I retrieved the above column value from oracle by using below statement:

      ResultSet rs = ((OracleCallableStatement)stmt).getCursor(2);
                
                while(rs.next()){
                     
                     setDataArray(rs.getString(1));// Ignore this line; its working fine
                     setDataArray(rs.getString(2));//Ignore this line; its working fine
                     Reader name_native = rs.getCharacterStream(3);
                     
                     
                }
                
      Now, I don't know how to convert above Reader object for JTextField to display Unicode value.

      Therefore, its my request to help me to resolve this issue, or may be I am not on the right path then please suggest me what to do; to accomplish the task i.e. display urdu in JTextField.

      Looking forward to your kind and positive response.

      Regards,

      M.A.Bamboat
      bamboat_3@hotmail.com

      Edited by: 883262 on May 24, 2012 11:09 AM
        • 1. Re: Display Unicode value in JTextField
          tschodt
          883262 wrote:
          I have a column in oracle table having data type as NCHAR, and carrying value in UNICode (i.e. its a person name in urdu language).

          Right now I retrieved the above column value from oracle by using below statement:
          ResultSet rs = ((OracleCallableStatement)stmt).getCursor(2);
                    
                    while(rs.next()){
                         
                         setDataArray(rs.getString(1));// Ignore this line; its working fine
                         setDataArray(rs.getString(2));//Ignore this line; its working fine
                         Reader name_native = rs.getCharacterStream(3);
                         
                         
                    }
          Now, I don't know how to convert above Reader object for JTextField to display Unicode value.
          How many characters are there (maximum)?

          [url http://docs.oracle.com/javase/6/docs/api/java/io/Reader.html#read%28java.nio.CharBuffer%29]Reader.read(CharBuffer)
          [url http://docs.oracle.com/javase/6/docs/api/java/nio/CharBuffer.html#allocate%28int%29]CharBuffer.allocate(capacity)
          [url http://docs.oracle.com/javase/6/docs/api/java/nio/Buffer.html#flip%28%29]Buffer.flip()
          [url http://docs.oracle.com/javase/6/docs/api/java/nio/CharBuffer.html#toString%28%29]CharBuffer.toString()
          static final int MAX = 1024;
             CharBuffer buffer = CharBuffer.allocate(MAX);
             int charactersRead = name_native.read(buffer);
             buffer.flip();
             String nameNative = buffer.toString();
             // now you should have a String 'nameNative' of length 'charactersRead'
          Edited by: tschodt on Jun 8, 2012 1:43 PM
          • 2. Re: Display Unicode value in JTextField
            DrClap
            Reader name_native = rs.getCharacterStream(3);
            What's wrong with simply this instead?
            String name_native = rs.getString(3);