Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB2: How to set encoding for db2clp under Windows?

I have a DB2 that was created with encoding set to UTF-8

db2 create database mydb using codeset UTF-8

My data insert scripts are also stored in encoding UTF-8. The problem now is that the command line processor seems to work with a different encoding as the Windows installation doesn't use UTF-8:

C:\Users\Administrator>chcp
Active code page: 850

This leads to the problem that my data (which contains special characters) is not stored correctly to the database.

Under Linux/AIX I could change the command line encoding by setting

export LC_ALL=en_US.UTF-8

How do I achieve this under Windows? I already tried

chcp 65001

UPDATE: But that won't have any effect? It seems like the db2clp can't deal with the UTF-8 encoded file because it will print out junk:

D:\Program Files\ibm_db2\SQLLIB\BIN>chcp 65001
Active code page: 65001

D:\Program Files\ibm_db2\SQLLIB\BIN>type d:\tmp\encoding.sql
INSERT INTO MY_TABLE (ID, TXT) VALUES (99, 'äöü');


D:\Program Files\ibm_db2\SQLLIB\BIN>db2 connect to mydb

Datenbankverbindungsinformationen

Datenbank-Server                                                = DB2/NT64 9.5.0
SQL-Berechtigungs-ID                                            = MYUSER
Aliasname der lokalen Datenbank                                 = MYDB

D:\Program Files\ibm_db2\SQLLIB\BIN>db2 -tvf d:\tmp\encoding.sql
INSERT INTO MY_TABLE (ID, TXT) VALUES (99, 'äöü')
DB20000I  Der Befehl SQL wurde erfolgreich ausgeführt.
like image 709
user1613270 Avatar asked Sep 14 '25 03:09

user1613270


1 Answers

You need to set both:

CHCP 65001
SET DB2CODEPAGE=1208

on the db2cmd command line, before running db2 -tvf. This works for databases that have CODESET set to UTF-8. To check the CODESET setup for database run:

db2 get db cfg for <your database>

and look for "Database code page" and "Database code set" they should be 1208 and UTF-8 respectively.

like image 122
Zoran Regvart Avatar answered Sep 16 '25 17:09

Zoran Regvart