hi i am trying to insert and fetch japanese characters into the database. i am using Oracle 9i and NLS_LANG and NLS_LANG_UTF shows JAPANESE_JAPAN.JA16SJIS and JAPANESE_JAPAN.AL16UTF-16 respectively. i am using Windows xp sp3 English operating system .
i have a jsp page in which i have 2 text fields where i enter japanese data ,then submit it to a servlet where i do a request.getParameter(""); and then insert in the database ,same way i want to fetch the japanese data from the database and show it on my browser. i am facing a lot of problems . Can one help me out .
Hello Mathew, The default server encoding is ISO-8859-1 which is capable of handling only the western European charatcers. To handle Asians locales, you have to use Unicode(utf8) encoding. Here is the code which will help you in retrieving values from client forms to Server.
String orig = request.getParameter(Constants.PARAM_NAME); String real = new String(orig.getBytes(),"UTF8"); But wait this is only retriving value from the form.
Second Step :
Store the values into database(Oracle) The database character set must be specified Unicode at the time of DATABASE CREATION. Oracle document strongly recommends to create unicode database rather than create database with default characters and then change the charset to Unicode. For database Storage :
Use prepared statements and parse these "real" String.
Third Step :
While retriving from database :
Convert the string again to Unicode with :
String stResultset = new String(rs.getString("COLUMN_NAME") ,"UTF8");
Step 4 : To Display this STring on the Screen :
Set the responsetype to Unicode using following line in your servlet. response.setContentType( "text/html; charset=UTF-8" );
NOw with Printwriter Object send the "stResultset" string back to the client.
Hope this helps.
The difference between winner and loser is making things happen and letting things happen.
posted 15 years ago
Thanx for the reply ,
i already have a database created . i dont know with which charset the database is installed .how do i know that ??
is it that depending on the charset the database is installed i have to encode my characters according to that.
Suppose my database is installed in shift_jis ,other than UTF-8 then what should i do ?
Can You give me some links about internationalization .
machines help you to do more, but experience less. Experience this tiny ad: