使用 UCanAccess 的 MS Access '97 数据库字符集

CharSet for MS Access '97 DB using UCanAccess

嘿,我正在使用 ucanaccess-5.0.0 读取数据库。 该数据库可能 < Access 2000,因为它不是 UTF-8。 看来我必须设置一个字符集。我尝试使用 url:

中的字符集参数

jdbc:ucanaccess://${databaseFile.absolutePath};memory=false;charSet=Cp1250

它似乎被忽略了,因为我仍然没有从数据库中取出我的德语变音符号。

我该怎么办?

工作解决方案:

class DatabaseOpener : JackcessOpenerInterface {
  override fun open(fl: File, pwd: String?): Database {
    return DatabaseBuilder.open(fl).apply {
      this.charset = charset("Cp1252")
    }
  }
}

// URL
"jdbc:ucanaccess://<path-to-mdb-file>;memory=false;jackcessOpener=${DatabaseOpener::class.qualifiedName!!}"

在 java 上:

public class CryptCodecOpener implements JackcessOpenerInterface {
    public Database open(File fl,String pwd) throws IOException {
        DatabaseBuilder dbd =new DatabaseBuilder(fl);
        dbd.setCodecProvider(new CryptCodecProvider(pwd));
        dbd.setCharset(Charset.forName("WINDOWS-1251"));
        return dbd.open();

    }

public class MainTest {
    public static void main(String[] args) throws IOException {
        String connUrl = "jdbc:ucanaccess://C:/GATE/Server/config.mdb";
        try {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            Connection conn =
                    DriverManager.getConnection(connUrl + ";jackcessOpener=com.example.demo.CryptCodecOpener");
            Statement st = conn.createStatement();
            String sql = "SELECT * FROM Users LIMIT 10";
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                System.out.println("\n" + rs.getString(1) + "\t" + rs.getString(3));
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

行家:

    <dependency>
        <groupId>net.sf.ucanaccess</groupId>
        <artifactId>ucanaccess</artifactId>
        <version>5.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.healthmarketscience.jackcess</groupId>
        <artifactId>jackcess-encrypt</artifactId>
        <version>3.0.0</version>
    </dependency>