Arrrgh! Where is the method to set encoding to insert into a table?
Posted in 1999
Hi, Consider the foll string in japanese. String original = new String("\\u4eca\\u65e5\\u306f\\u4e16\\u754c"); while writing to a file one must use "SJIS" to specify the correct encoding, otherwise it uses the *default* file encoding of the system. For example; BufferedWriter write=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("filename"),***"SJIS"***)); write.write(line,0,line.length()); line is the byte array for the original string. write.flush(); This encodes correctly to SJIS and can be read in properly. BufferedWriter write=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("rwwrite.html"),)); write.write(line,0,line.length()); write.flush(); This encodes to ???? (A bunch of question marks (0x3f)) ... Yes, that is how they are stored and *not* only how it appears notepad! So basically the type of ENCODING MUST be specified during writing to a file. But when using a insert statement to dump it into a database, how do I set the encoding? All I can do is, String name=new String("\\u4eca\\u65e5\\u306f\\u4e16\\u754c"); String cmd = "insert into table_name (name) values ('"+name+"')"; stmt.executeUpdate(cmd); There isnt any place to set the encoding! Its stored as ???? in the database! Is this a database issue? ... Im using informix ... any ideas? Do i need to install the unicode datablade in Informix and gls support? Im going crazy with this! TIA, Carlos btw, I dont want to store it as bytes I want to store it as a varchar or univarchar ... Storing it as bytes works fine.