更新时间:2023-02-06 08:46:23
正如@Scratte 正确指出的那样,rs.getString(1)
正在返回一个已经包含替换字符的字符串.感谢他帮助我指出这个问题和本次讨论
As @Scratte correctly pointed out, rs.getString(1)
was returning a String that already contained replacement characters. Thanks for his help in pointing me towards this question and this discussion
我最终实现了一个 ucanaccess JackcessOpenerInterface
并且工作得很好
I ended up implementing a ucanaccess JackcessOpenerInterface
and worked wonderfully
package com.company.somepackage;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import net.ucanaccess.jdbc.JackcessOpenerInterface;
public class CharsetOpener implements JackcessOpenerInterface {
public Database open(File f, String pwd) throws IOException {
DatabaseBuilder db = new DatabaseBuilder(f);
db.setCharset(Charset.forName("ISO-8859-1"));
try {
db.setReadOnly(false);
return db.open();
} catch (IOException e) {
db.setReadOnly(true);
return db.open();
}
}
}
以及在我的连接生成器中的实现:
And for the implementation in my Connection generator:
public static Connection baseAccess(String base) {
try {
java.util.Properties propiedades = new java.util.Properties();
propiedades.put("jackcessOpener", "com.company.somepackage.CharsetOpener");
return DriverManager.getConnection(String.format("jdbc:ucanaccess://%s", base),propiedades);
} catch (SQLException ex) {}
}
请注意,实际属性是 jackcessOpener
,并且必须指向完全限定的类名.
Notice that the actual property is jackcessOpener
and must point to a fully qualified class name.