db2的字符集是数据库上的特性,同一个实例下的数据库可以有各自不同的字符集,例如:
create database testdb on ‘e:’ using codeset gbk territory cn with ‘baal”s test db’
则会创建一个1386(cn)的数据库
当客户端连接到数据库的时候,他们的字符集要相互兼容,否则就会报下边类似的错误:
$ db2 connect to lord
SQL0332N Character conversion from the source code page “819″ to the target
code page “1386″ is not supported. SQLSTATE=57017
上边的错误则说明server端的字符集是819的,而客户端的字符集是1386(cn)的,db2不能server端819的字符集转化为client端1386的字符集。解决这个问题的思想是将client端的字符集改为与server端兼容的:
例如上例可以将client端字符集改为819或者1208(utf-8),步骤:
$ db2set db2codepage=819 —–或者Unicode(UTF-8) 1208
$ db2set db2country=US
$ db2 terminate
$ db2stop force
$ db2start
这样客户端的字符集就变为819活着1208,再连接就不会报错。