gpt4 book ai didi

java - postgresql 驱动程序 9.4 和 Postgres 安装 9.6 的 UTF-8 序列无效

转载 作者:行者123 更新时间:2023-12-01 08:51:18 25 4
gpt4 key购买 nike

我已经安装了最新的 PostgreSQL 版本:9.6

我正在使用 postgresql 驱动程序版本 9.4-1206-jdbc42 - 我在 Maven 存储库中找不到更新的版本。

当我尝试连接时,出现异常:

Caused by: java.io.IOException: Ungültige UTF-8-Sequenz: das erste Byte ist 10xxxxxx: 179
at org.postgresql.core.UTF8Encoding.decode(UTF8Encoding.java:98)
at org.postgresql.core.PGStream.ReceiveString(PGStream.java:327)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:424)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:203)
... 49 more

应用程序部署在 OSGi 容器中,数据源使用 PAX 配置文件配置:

osgi.jdbc.driver.class=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/test
dataSourceName=test
user=test
password=test
protocolVersion=3

这里出了什么问题?这是驱动版本和数据库安装之间不兼容吗?我应该降级吗?

数据库使用UTF-8编码。

在独立的java应用程序中,以下代码是成功的:

    ConnectionPool pool = new ConnectionPool();
pool.setUrl("jdbc:postgresql://localhost:5432/test");
pool.setUser("test");
pool.setPassword("test");
pool.setProtocolVersion(3);
Connection conn = pool.getConnection();

所以看起来更像是 PAX 问题...

最佳答案

实际问题出在其他地方。在 pg_hba.conf 中将授权方法从“md5”更改为“trust”后,我收到了真正的错误消息:找不到角色“test”。

PAX 在用户名后附加了尾随空格,这很容易监督,并且 PostgreSQL 驱动程序无法解码来自服务器的错误消息。

关于java - postgresql 驱动程序 9.4 和 Postgres 安装 9.6 的 UTF-8 序列无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42385811/

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