我有一个问题,当我连接到使用JDBC PostgreSQL数据库。我已经从pgAdmin3网站上的软件包下载安装了postgresql 9.1(我需要gui)。我连接到DB蒙山pgAdmin的,没有任何问题,但是当我试图从Java代码连接,我已经相继式的错误:JDBC + Postgres的连接问题
org.postggresql.util.PSQLException: FATAL: password authentication failed for user 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);
}
}
显然你已经提供了错误的密码。顺便说一句:你应该使用的网址:'JDBC:在PostgreSQL://服务器/ coffeeDB'其中服务器是运行PostgreSQL的计算机的名称。如果它在同一台机器上,也可以使用'localhost'。 – 2012-04-08 18:12:14
我已经尝试做到这一点,但它不起作用。密码是正确的,因为是我使用的pgAdmin的GUI连接到我已经解决了DB – giozh 2012-04-08 18:16:58
相同。该网址需要同时指定端口 – giozh 2012-04-08 18:31:36