aspose file tools*
The moose likes JDBC and the fly likes Cannot insert chinese/thai characters in db2 through script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Cannot insert chinese/thai characters in db2 through script" Watch "Cannot insert chinese/thai characters in db2 through script" New topic
Author

Cannot insert chinese/thai characters in db2 through script

Rahul Vhatkar
Greenhorn

Joined: Aug 24, 2009
Posts: 9
I have a db2 script that tries to insert some thai characters in a certain column of a table. The contents of that script is somewhat like this:
insert into thmsg (name, thvalue) values ('aaaa', 'ประเทศไทย');

I saved that script in UTF-8 format. Name of the file is thai.sql.

Then I started the DB2 Command Line Processor (CLP) and executed the following command : db2 -tvf thai.sql
Garbage values were inserted in the thmsg table for thvalue column.

But if I execute the same script via some editor, then correct value gets stored.

Any idea how can I get it working via DB2 CLP?
Alan Hampson
Ranch Hand

Joined: Apr 10, 2009
Posts: 31
Which command line, Linux or Windows?

Because this works with a DB editor, but not from the command line, I'd guess that your command prompt is not utf8. What happens if you display the contents of the file using the command line without any editor?

Rahul Vhatkar
Greenhorn

Joined: Aug 24, 2009
Posts: 9
I have a Windows machine. When i display the script file contents, I cannot see the thai characters. Instead I see the following garbled characters -
'ประเทศไทย'

Is db2cmd not UTF-8?
Or is there any way to run this script without using an editor?
Alan Hampson
Ranch Hand

Joined: Apr 10, 2009
Posts: 31
db2cmd is probably OK with utf8, the problem is that the Windows command prompt isn't. That's why you see the weird characters when you type the file.

So the command prompt is probably causing problems with db2cmd. According to what I just read (here) the solution is to change the code page with the chcp command and use a unicode compliant font (Lucida console is recommended).

I can't speak to this with great authority, since I use Linux most of the time. Take a look at the link and see what you think.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot insert chinese/thai characters in db2 through script