We help IT Professionals succeed at work.

Korean Characters

rospcc
rospcc asked
on
Medium Priority
748 Views
Last Modified: 2013-12-03
Hi,

I am having a problem in storing korean characters in MSSQL database using JSP. I had this problem previously on Thai characters, and somebody solved it for me by adding in this tag on the JSP page.

<%@ page pageEncoding="UTF-8"%>

And before I did any request.getparameter() , I just need to add in another tag:
request.setCharacterEncoding("UTF-8");

By using this, it solved the Thai problem, the thai characters will be stored exactly into the database.


Now, it seems that I can't use this same solution for storing and displaying korean characters. Everything will be stored as ??????? (Questions marks)


BUT, it works if I store the characters in this formatl, &#12615;&#12609;&#12615;&#12603;

I'm not sure whether we can use UTF-8 for korean characters. When I used this tag:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>

Then it works, but storing this format into the db:&#12615;&#12609;&#12615;&#12603;


I want to store exactly the korean characters into the MSSQL, not in the format above. Could anybody give me some suggestions?



Regards,
rospcc
Comment
Watch Question

Hi,

I think that you can try from the list of encodings in this URL.

http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html

Additionally, do not forget to include charsets.jar into your app if you use the extended encoding.

David
Btw,

Let me try that :)

David

Author

Commented:
Hi David,

Thanks for the information, at least I have something to start on. And one more information for you to take note, I need the JSP to be able to show both Korean and Thai characters. My current implementation can only work for one at a time. When I use UTF-8, it only works for Thai. When I use another encoding, it only works for Korean.


Regards,
Jenty
Hi,

Is this the problem on storing your Korean into DB or the way it renders to JSP?

I think that Korean should also be available in UTF-8

David

Author

Commented:
Yes, I wanted to store the Korean characters into DB. Now I can only store THai if I use UTF-8
Mmm....

Okay, to render it to JSP, it is okay to use UTF-8 as UTF-8 should be able to handle Korean as well. The problem would be on the way you save the data into DB.

Can you post your JSP to store the data to DB? I need to see your Java codes as well. What is the type of column that you use to store this foreign language in MSSQL

Thanks
David

Author

Commented:
Ok, the datatype of the field is nvarchar. On top of every jsp codes I will also add request.setCharacterEncoding("UTF-8"); to make sure that all user inputs will be converted to UTF-8.

Here is my java codes of insertion to the database:

public void addRecord(String name) throws SQLException, Exception {                        

     String sql = "Insert into TB_Competency (CompetencyName) values ('" + name + "')";
            
                                //another function to open database connection            
            db.openDB();            
            PreparedStatement ps = db.getCon().prepareStatement(sql);
                  
            ps.executeUpdate();
                  
            db.closeDB();
            
                        

}

Is there anything that has to do with the database collation? I am using the default one which seems being set as Thai...But anyway I tried to change to Korean, it didn't work either.

Commented:
Hi,

UTF-8 for jsps is all correct for handling korean. In terms of DB you need to change the character encoding in the database.The character set of the database server is chosen during the MSSQL installation and cannot be changed. That means that one server can support only one character set. Use the unicode data types it supports storing of all character sets.

May be u need to shutdown the database, change the character encoding and start again. Please check more with the database administrator about it.

fargo

Hi,

Sorry, I was away in the weekend.

If you can insert Thai characters correctly using UTF-8, you should not have a problem on inserting Korean characters to DB as well. It could be a problem on DB side as what fargo suspected.

David

Author

Commented:
Hi,

I suspected so too..I'll take a look at the DB site first, will come back to you guys...Thanks.


Cheers,
rospcc

Author

Commented:
Hi,

If I tried to key in straight away to DB, which is throuh Enterprise Manager, it was alright. And when I tried to display from JSP, it was alright too. Only when I inserted from JSP and passed through Java, then it didn't work.


Regards,
rospcc
Hi,

Weird. It should work fine. Let me check your codes again.

David
Hi,

Try to add
<%@page language="java" contentType="text/html;charset=UTF-8"%>

at top on every of your JSP. Honestly, they should be the same but just give it a try ;)

David

Author

Commented:
I have added that. Sorry I forgot to post some more information. I found out the problem is not with the JSP or the application, but with the MSSQL setting itself. I think it has to do with the DB Collation.

When I set the collation to Korean_Wansung_CI_AS, it works alright whether you insert from DB direct or from JSP. Now, my problem is, we have to cater for different languages to be stored in one database. Currently, we have Thai and Korean. So, if I set the collation to Korean, it cannot accept Thai anymore. I wonder whether Microsoft does allow to store different languanges in a database.


Regards,
rospcc
Glad you have found the problem.

For better solution, you may be interested asking that DB Collation in the MS SQL Forum in EE.


David
Commented:
PAQed with points refunded (500)

GranMod
Community Support Moderator

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.