Search code examples
spring-bootsybaseliquibase

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


I am trying to save Chinese characters in Sybase database with Liquibase, but ended up getting "?" for each of the characters. I referred this

but it didn't help.

I am using the 3.6.1 version of liquibase-core (also tried with 3.6.3)

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

Here are the contents of CREATE and INSERT scripts CREATE 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>

INSERT Query:

<?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>

And when I start the Spring Boot application, the scripts get executed. And I get "??" in place of "汉字" when I query the table.

As in the code, I have already put encoding=utf8. Not sure what is missing.

Sybase version: ASE 15.

Any help is appreciated.


Solution

  • And the solution lies in the DB connection params.

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