[英]JDBC + postgres connection problems
當我使用 jdbc 連接到 postgresql 數據庫時出現問題。我從 pgAdmin3 站點上的 package 下載安裝了 postgresql 9.1(我需要 gui)。 我連接到 db whith pgAdmin 沒有問題,但是當我嘗試從 java 代碼連接時,我遇到了后續錯誤:
org.postggresql.util.PSQLException:致命:用戶 postgres 的密碼驗證失敗
拋出異常的代碼是
public class ConnectionManager {
private ConnectionManager(){};
private static boolean driverLoad = false;
private static final String pgDriver="org.postgresql.Driver";
private static final String pgUrl="jdbc:postgresql:coffeeDB";
private static final String usr="postgres";
private static final String psw="password";
public static Connection getConnection() throws ClassNotFoundException, SQLException {
if(!driverLoad) {
Class.forName(pgDriver);
driverLoad=true;
}
return DriverManager.getConnection(pgUrl, usr, psw);
}
}
我解決了 postgresql的URL上添加默認端口即可
我在 Play 2.2 中得到了這個。 略有不同的味道
[error]c.j.b.h.AbstractConnectionHook - Failed to obtain initial connection Sleeping for 0ms and trying again. Attempts left: 0. Exception: null.Message:FATAL: password authentication failed for user "root"
問題是 application.conf 中 url 周圍的引號。 如果有特殊字符,需要引號
失敗
db.default.url=jdbc:postgresql://myMachine:5432/mydb
作品
db.default.url="jdbc:postgresql://myMachine:5432/mydb"
密碼也一樣
失敗
Passw)rd#!
作品
"Passw)rd#!"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.