开发者

DB2 database using unicode

I have a problem with DB2 databases that should store unicode characters. The connection is established using JDBC.

What do I have to do if I would like to insert a unicode string into the database?

INSERT INTO my_table(id, string_field) VALUES(1, N'my unicode string');

or

INSERT INTO my_table(id, string_field) VALUES(1, 'my 开发者_如何转开发unicode string');

I don't know if I have to use the N-prefix or not. For most of the databases out there it works pretty well when using it but I am not quite sure about DB2. I also have the problem that I do not have a DB2 database at hand where I could test these statements. :-(

Thanks a lot!


The documentation on constants (as of DB2 9.7) says this about graphic strings:

A graphic string constant specifies a varying-length graphic string consisting of a sequence of double-byte characters that starts and ends with a single-byte apostrophe ('), and that is preceded by a single-byte G or N. The characters between the apostrophes must represent an even number of bytes, and the length of the graphic string must not exceed 16 336 bytes.


I have never heard of this in context of DB2. Google learns me that this is more MS SQL Server specific. In DB2 and every other decent RDBMS you only need to ensure that the database is using the UTF-8 charset. You normally specify that in the CREATE statement. Here's the DB2 variant:

CREATE DATABASE my_db USING CODESET UTF-8;

That should be it in the DB2 side. You don't need to change the standard SQL statements for that. You also don't need to worry about Java as it internally already uses Unicode.


Enclosing the unicode string constant within N'' worked through JDBC application for DB2 DB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜