How to insert and retrieve Unicode characters > 255 in Microsoft Access Database

I want to set up a database table in MS Access using the matlab database toolbox. The database should contain at text field with artist names. The names can contain unicode charaters with code > 255. However it seems that in my implementation the Access Database only is correct for unicode characters <= 255.
Here is the code I use:
% determine character set
cset = feature('DefaultCharacterSet');
fprintf('Default Character Set: %s\n',cset);
% connect to database, database is empty (no tables)
dbname = 'Database3';
conn = database(dbname,'','');
% Create Table1 and insert 2 records into Table1
ArtistName1 = 'ABBA';
ArtistName2 = char(250:260); % corresponds to string 'úûüýþÿĀāĂăĄ'
data_in = table({ArtistName1; ArtistName2},'VariableNames',{'Artist'});
tablename = 'Table1';
coltypes = "varchar(255)";
sqlwrite(conn,tablename,data_in,'ColumnType',coltypes)
% read back Table1
data_out = sqlread(conn,tablename);
% print written and red Artist names
fprintf('Artist names written to table: %s %s\n', char(data_in{1,1}), char(data_in{2,1}));
fprintf('Artist names red back from table: %s %s\n', char(data_out{1,1}), char(data_out{2,1}));
The result is:
Default Character Set: windows-1252
Artist names written to table: ABBA úûüýþÿĀāĂăĄ
Artist names red back from table: ABBA úûüýþÿ
As one can see artist name 2 fails for unicode characters with code >255.
Is there a solution to modify the matlab code to handle also unicode characters with code >255?

Answers (1)

To make MATLAB to handle it correcly, you will need to modify locale setting on your Windows machine to fix it.
1. Control Panel -> Clock and Region -> Region
2. Click on the “Administrative” tab
3. Click on “Change system local” and check the checkbox “Beta: Use Unicode UTF-8 for worldwide language support” (Refer image below)
4. Restart your machine.
5. The issue should be fixed now.

Products

Release

R2020a

Asked:

on 25 Apr 2020

Answered:

on 13 Jan 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!