使用 JDBC 连接到数据库时出现连接错误。但是,我可以使用 psql 连接到同一个数据库。这是我的连接字符串:
"jdbc:postgresql://127.0.0.1:5432/sample?user=postgres&password=postgres&loglevel=2"
我在连接时看到以下日志,然后是 PSQLException。
16:33:49.425 (1) PostgreSQL 9.1 JDBC4 (build 901)
16:33:49.431 (1) Trying to establish a protocol version 3 connection to 127.0.0.1:5432
16:33:49.443 (1) FE=> StartupPacket(user=postgres, database=sample, client_encoding=UTF8, DateStyle=ISO, extra_float_digits=2)
16:33:49.448 (1) <=BE AuthenticationReqMD5(salt=da8b7230)
16:33:49.449 (1) FE=> Password(md5digest=md5dc7d3827e761b7b18f553d6bdd15fa21)
16:33:49.451 (1) <=BE AuthenticationOk
16:33:49.467 (1) <=BE ErrorMessage(FATAL: database "sample" does not exist)
org.postgresql.util.PSQLException: FATAL: database "sample" does not exist
但是,我可以使用 psql 命令正常连接
$ psql -U postgres sample
psql (9.1.4)
Type "help" for help.
sample=#
我还能尝试隔离问题吗?