简体和繁体中文字符存储为?在 Spring 引导项目中使用 Liquibase 在 Sybase 数据库中

Simplified and Traditional Chinese characters are stored as ? in the Sybase database using Liquibase in Spring Boot project

我试图用 Liquibase 在 Sybase 数据库中保存汉字,但最后得到的是“?”对于每个角色。 我提到了 this

但没有用。

我使用的是 3.6.1 版的 liquibase-core(也尝试过 3.6.3)

  <dependency>
      <groupId>org.liquibase</groupId>
      <artifactId>liquibase-core</artifactId>
      <version>3.6.1</version>
  </dependency>

这是 CREATE 和 INSERT 脚本的内容 创建 Table:

<?xml version="1.0" encoding="UTF-8"?>
    <databaseChangeLog
            xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
            xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
                            http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd" >

        <changeSet author="me" id="1" >
            <createTable tableName="person" >
                <column name="name" type="unitext" encoding="utf8" >
                </column>
                <column name="address" type="VARCHAR(255)" />
            </createTable>
            <rollback>
                <dropTable tableName="person"/>
            </rollback>
        </changeSet>
    </databaseChangeLog>

插入查询:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

<changeSet author="me" id="2" runOnChange="true" >
    <insert tableName="person" >
        <column name="name" value="汉字" encoding="utf8"/>
        <column name="address" value="DNI"/>
    </insert>
</changeSet>

当我启动 Spring 启动应用程序时,脚本就会执行。我得到“??”当我查询 table.

时代替“汉字”

和代码一样,我已经设置了encoding=utf8。不确定缺少什么。

Sybase 版本:ASE 15。

感谢任何帮助。

除了您没有指定您正在使用的 Sybase 数据库类型(有 3 种不同的 Sybase 数据库产品)之外,您显示的是客户端东西的。同样重要的是服务器是否设置为支持 Unicode 字符(支持的各种方式)。这就是你需要找出的。

解决方案在于数据库连接参数。

jdbc:sybase:host:port?useUnicode=true&CHARSET=utf8