【问题标题】:TableView data encoding in JavaFXJavaFX 中的 TableView 数据编码
【发布时间】:2016-04-07 03:44:27
【问题描述】:

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

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

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

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;
            }       
        }
    }

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

【问题讨论】:

  • 我看到标题很好。您从哪里填充数据?
  • @Eng.Fouad 是的,所有 UI 元素标签都很好,只有数据库中的数据编码不正确。添加代码发布(我在init方法中调用Platform.runLater中的服务)。

标签: java maven javafx javafx-8


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-16
    • 2014-10-14
    • 2017-12-13
    • 2015-10-01
    • 2015-09-17
    • 2015-12-10
    • 2016-11-18
    • 1970-01-01
    相关资源
    最近更新 更多