I have a running local instance of PostgreSql on a linux machine. When I use psql
command from the shell I success to log in without any problem. I need to connect to the PostgreSql via the JDBC, but I don't know what exactly should I pass as url
parameter to DriverManager.getConnection()
.
It should start with jdbc:postgresql:
but what's going next?
I was told by the system group that a database with was created like user name. e.g. if my user is jutky
a db named jutky
was created, but when I try to open a connection to jdbc:postgresql:jutky
I get an error
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "jutky"
:(
Additional info
When I login via the psql
I'm not prompted for the password, so when I try to login via JDBC I pass an empty string as a password - is it correct, or should I pass null
or something?
When I type psql --help
in the shell I see among the rest this line:
Connection options:
-h, --host=HOSTNAME database server host or socket directory (default: "/var/run/postgresql")
So I understand that I connect to PostgreSql via a socket directory
, does that matters something to the URL string in the JDBC?
EDIT
First thanks for the answers.
Second: its not first time I'm using JDBC and in particular not the first time I'm connecting to the PostgreSql from JDBC, so I know the general rules and I have read the documentations. However in the described case I'm not sure how exactly should I construct the connection string if the instance is running via the socket directory
and what password should I provide. Because when I login via the psql
I'm not prompted for password at all.
Thanks in advance.