gpt4 book ai didi

java - 是否可以在没有密码的情况下创建 jdbc 连接(使用 postgresql 'trust' )?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:47:39 24 4
gpt4 key购买 nike

我正在使用 jdbc 连接到 java 应用程序中的 postgresql 数据库(实际上该应用程序是用 Groovy 编写的)。我已将 postgresql 设置为使用“信任”身份验证方法。是否可以在不指定密码的情况下打开 jdbc 连接?当我尝试使用带有空白密码的普通构造函数时,它失败并显示

Exception in thread "Thread-2" org.postgresql.util.PSQLException: FATAL: password authentication failed for user "myuser"

即使在命令行中,这也能正常工作

psql -U myuser mydatabase
Welcome to psql 8.3.5, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

最佳答案

是的,你可以。

请注意,Postres JDBC 驱动程序始终使用 IP 套接字(pg_hba.conf 中的host),即使数据库在本地机器上,psql 可以使用本地套接字(pg_hba.conf 中的local)。因此,如果 psql 使用 trust 身份验证而 JDBC 不使用,您可能应该为 IP 套接字配置 trust 身份验证,see documentation .

关于java - 是否可以在没有密码的情况下创建 jdbc 连接(使用 postgresql 'trust' )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2832966/

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