I've a problem when i'm connecting to a postgresql database with jdbc. I've install postgresql 9.1 from a package download on the pgAdmin3 site (i needed gui). I'm connecting to db whith pgAdmin with no problems, but when i try to connect from java code, i've the sequent error:
org.postggresql.util.PSQLException: FATAL: password authentication failed for user postgres
the code that throws the exception is
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://servername/coffeeDB
where servername is the name of the machine that runs PostgreSQL. Alternatively uselocalhost
if it's on the same machine.