HSQLDB可以在创建表格之后,通过挂载csv文件来导入数据。HSQLDB默认编码是ASCII,在导入UTF-8的表格时候出现了乱码。解决方法:
- csv用sublime等工具存储为utf-8(确保格式一致)
- hsqldb命令指定
encoding=utf-8
如下:
drop table student IF EXISTS;
Create Text table student (
stu_id char(10) primary key,
name varchar(20),
dept varchar(20),
class varchar(20),
stu_type varchar(20),
email varchar(50),
tel char(11));
SET TABLE student SOURCE "xueshengmingdan.csv;fs=,;encoding=UTF-8";
select * from student;
官方文档如下:
The character encoding for the source file is ASCII by default, which corresponds to the 8-bit ANSI character set. To support UNICODE or source files prepared with different encodings this can be changed to UTF-8 or any other encoding. The default is encoding=ASCII and the option encoding=UTF-8 or other supported encodings can be used. From version 2.3.4, the two-byte-per-character encodings of UTF-16 are also supported. The encoding=UTF-16BE is big-endian, while encoding=UTF-16LE is little-endian. The encoding=UTF-16 is big-endian by default. This encoding reads a special Unicode character called BOM if it is present at the beginning of an existing file and if this character indicates little-endian, the file is treated as such. Note HSQLDB does not write a BOM character to the files it creates from scratch.