gpt4 book ai didi

java - JavaFX 中的 TableView 数据编码

转载 作者:搜寻专家 更新时间:2023-11-01 03:35:01 25 4
gpt4 key购买 nike

我在 Eclipse 和 Firebird 数据库中有一个 Maven JavaFX 项目,使用 UTF-8 表编码(表中的数据为俄语)。当我尝试使用命令 jfx:ru​​n 从 Eclipse 运行它时 - 它成功了并且在 TableView 中我看到所有数据都是正确的。

enter image description here

但是,当我尝试使用命令 jfx:native 创建 native 安装程序并设置结果包时,TableViews 中的所有数据都是不正确的编码(通过互联网搜索获取提示,需要从 转换数据UTF-8WINDOWS-1251)

enter image description here

从数据库中填充数据的代码:

private class GetClientListTask extends Task<ObservableList<Client>> {
@Override
protected ObservableList<Client> call() throws Exception {
try (Connection connection = DriverManager.getConnection(App.DB_CONNECTION_STRING, App.DB_USERNAME, App.DB_PASSWORD)) {
com.zvpblog.KomstarService.model.jooq.tables.Client t = com.zvpblog.KomstarService.model.jooq.tables.Client.CLIENT;
DSL.using(connection).
selectFrom(t).
orderBy(t.CLIENTID.desc()).
fetch().
map(rs -> new Client(rs.getClientid(), DateTimeUtils.convertToLocalDate(rs.getRegdate()), rs.getLname(), rs.getFname(), rs.getMname(), rs.getGender(), DateTimeUtils.convertToLocalDate(rs.getBirthdate()), rs.getAddress(), rs.getPhone())).
forEach(c -> clients.add(c));
clientTableViewData = FXCollections.observableArrayList(clients);
return clientTableViewData;
} catch (SQLException e) {
LOGGER.error(e);
return null;
}
}
}

为什么在运行模式下编码是正确的,但在原生包中是不正确的?

最佳答案

将连接属性 charSetencoding 设置为 UTF8 解决了从数据库填充数据和向数据库插入数据的问题。

...
Properties connectionProperties = new Properties();
...
connectionProperties.put("charSet", "UTF8");
connectionProperties.put("encoding", "UTF8");
...
Connection connection = DriverManager.getConnection(App.DB_CONNECTION_STRING, App.connectionProperties)
...

关于java - JavaFX 中的 TableView 数据编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34575737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com