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

moj*_*nes 8 java postgresql jdbc

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

Exception in thread "Thread-2" org.postgresql.util.PSQLException: FATAL: password authentication failed for user "myuser"
Run Code Online (Sandbox Code Playgroud)

即使从命令行,这工作正常

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
Run Code Online (Sandbox Code Playgroud)

axt*_*avt 5

是的你可以.

请注意,Postres JDBC驱动程序始终使用IP套接字(hostin pg_hba.conf),即使数据库位于本地计算机上,psql也可以使用本地套接字(localin pg_hba.conf).因此,如果psql使用trust身份验证和JDBC不兼容,您可能应该trust为IP套接字配置身份验证,请参阅文档.