Storing and displaying foreign characters to and from oracle in Java.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   timj_das
Posted On:   Tuesday, May 21, 2002 07:55 AM

Hi there, here is a brief description of the environment. JRun webserver hosing java beans, servlets and jsps on Solaris. And a Oracle 8i db storing data. Now the problem is this system needs to support multi language. I tried the following, and none of them worked... Method[1]: Got a text file containing Chinese characters like '年第十三届金曲奖颁奖结果终于于5月4日揭晓' this encoded in Unicode. I can read this file using this function... public static String readInput(String fileName, String encoding) { StringBuffer buffer = new StringBuffer(); try { FileInputStream fis = new FileInputStream(fileName); InputStream   More>>


Hi there, here is a brief description of the environment. JRun webserver
hosing java beans, servlets and jsps on Solaris. And a Oracle 8i db storing
data. Now the problem is this system needs to support multi language.


I tried the following, and none of them worked...


Method[1]: Got a text file containing Chinese characters like '年第十三届金曲奖颁奖结果终于于5月4日揭晓'
this encoded in Unicode. I can read this file using this function...


public static String readInput(String fileName, String
encoding) {



StringBuffer buffer = new StringBuffer();


try {



FileInputStream fis = new FileInputStream(fileName);


InputStreamReader isr = new InputStreamReader(fis,
encoding);


Reader in = new BufferedReader(isr);


int ch;


while ((ch = in.read()) > -1) {
buffer.append((char)ch); }


in.close(); return buffer.toString();



}catch (IOException e) { e.printStackTrace(); return
null; }



}


The return string from this function is encoded correctly and I can save it
into a file, which when displayed, shows the characters correctly. But when I
try to save the same string in Oracle, the string gets replaced and looks like 't,A
JÑòV¿VÓ¿È¿¿5 4åíS ๾¿¿c{ÑòL¿L '. The column is of
type LONG in Oracle and the Language set is UTF-8.


Method[2]. I use the follwowing method to conver the entire chinese string
into unicode using the following methods.


static public String byteToHex(byte b) {
// Returns hex String representation of byte b


    char hexDigit[] = { '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };


    char[] array = { hexDigit[(b
>> 4) & 0x0f], hexDigit[b & 0x0f] };


    return new String(array);


}


static public String charToHex(char c) {
// Returns hex String representation of char c


    byte hi = (byte) (c >>> 8);


    byte lo = (byte) (c & 0xff);


    return byteToHex(hi) + byteToHex(lo);


}


It comes in as dddx format. If i try to add a unicode escape sequence like u
so that it is saved in oracle as udddx format. I have to use String s =
"\u" + UnicodeFormater.charToHex(chineseString.getCharAt(i)). Now
when i display this stored unicode string in a browser it displays only the
string as u234x etc and ignores the escape sequence.


None of method 1 or 2 seems to work, any idea of whats going wrong. Any other
suggestions...


Thanks in advance!





   <<Less

Re: Storing and displaying foreign characters to and from oracle in Java.

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, May 21, 2002 09:14 AM

Sorry, the Republicans who stole the last election in the US have passed a law mandating English language only, in databases (and no dirty words, either) ...



ho ho, just kidding.



Are you using Oracle's "thin" JDBC driver from "classes12.zip"?



Have you checked Oracle's MetaLink documentation, or their OTN (both at their Web site -- Metalink is for paid support customers, OTN is free) for any suggestions, on how best to represent & store & retrieve Unicode (non-ASCII) strings in their database, through their JDBC driver?

About | Sitemap | Contact