我遵循了以下教程:
http://examples.javacodegeeks.com/core-java/java-postgresql-example/
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:257)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:159)
at org.postgresql.Driver.makeConnection(Driver.java:415)
at org.postgresql.Driver.connect(Driver.java:283)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.javacodegeeks.examples.TestConnection.main(TestConnection.java:16)
Caused by: java.io.IOException: Illegal UTF-8 sequence: initial byte is 11111xxx: 252
at org.postgresql.core.UTF8Encoding.decode(UTF8Encoding.java:125)
at org.postgresql.core.PGStream.ReceiveString(PGStream.java:329)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:424)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:203)
... 7 more
我正在使用 Eclipse 并在我的项目中添加了最新的 PostgreSQL JDBC 驱动程序(重命名为 postgres.jar),我的代码如教程所示。
我相信 PostgreSQL 服务器正在运行,我正在使用 Windows 10 并运行“pg_ctl start -D”,路径是正确的,据我所知服务器似乎正在工作
我已经在 pgAdmin 中检查过,数据库编码是 UTF8。
有人可以帮忙吗?
最佳答案
我遇到了同样的问题。通过为我尝试连接的用户设置密码解决了这个问题。旧版本的 JDBC 驱动程序提供了有用的错误消息。
关于java.io.IOException : Illegal UTF-8 sequence: initial byte is 11111xxx: 252 - Eclipse and PostgreSQL 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34729845/