JDBC Connect Error Postgresql

C

Chase Preuninger

I started my Postgres DBMS and I can connect to it through the
services window in Netbeans but I can seem to connect using code.
Also I do have the dirver int the class path which passes the
Class.forName("driver"); test.

System.setProperty("jdbc.drivers", "org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql:////
127.0.0.1//Notes", "myun", "mypw");

Exception in thread "main" org.postgresql.util.PSQLException: The
connection attempt failed.
at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:
137)
at
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:
66)
at
org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:
124)
at
org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:
30)
at
org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:386)
at org.postgresql.Driver.connect(Driver.java:260)
at java.sql.DriverManager.getConnection(DriverManager.java:
582)
at java.sql.DriverManager.getConnection(DriverManager.java:
185)
at
com.cpsoft.mynotes.database.accounts.DatabaseAccount.main(DatabaseAccount.java:
17)
Caused by: java.net.UnknownHostException: /
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at org.postgresql.core.PGStream.<init>(PGStream.java:62)
at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:
77)
... 9 more
Java Result: 1
 
C

Chase Preuninger

I think I found the problem because it works if the database URL is
"jdbc:postgresql:Notes" but why?
 
A

Arne Vajhøj

Chase said:
I think I found the problem because it works if the database URL is
"jdbc:postgresql:Notes" but why?

Connection conn =
DriverManager.getConnection("jdbc:postgresql://localhost/Notes", "myun",
"mypw");

should work. And you will need to specify the host if it
is not localhost.

Arne
 
C

Chase Preuninger

Also I put in the extra slashes because it was a string literal so
therefore every two slashes would become just one slash.
 
D

Daniele Futtorovic

Also I put in the extra slashes because it was a string literal so
therefore every two slashes would become just one slash.

BACKslashes.

If it doesn't work with two slashes, check whether eth0 is up.
 
A

Arne Vajhøj

Chase said:
Also I put in the extra slashes because it was a string literal so
therefore every two slashes would become just one slash.

That is necessary for \ not for /.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top