0
votes

I know my message can seem a duplicate of another, but I don't think so. Tell me if I'm wrong.

I just finished a free software in Java/swing/postgresql. It was successfully tested on Windows and Linux.

Now I am trying to make the documentation of it, and I'm on the "Installing postgresql server" part of the documentation.

The problem is that I can't remember what I've done to make the application work with PostgreSQL (I know it's lame...).

The JDBC string is made this way in the code:

// Open the SQL Connection 
m_sql_connection = DriverManager.getConnection("jdbc:postgresql://"+m_postgresql_server_name+":"+m_postgresql_port_number+"/"+m_postgresql_database_name, "postgres", "<not empty>");

The facts:

  • I work on a Windows 7 machine 64 bit
  • The PostgreSQL server is running (I see the service Started)
  • The PostgreSQL server configuration seems OK
  • I use login: postgres / pass: in my JDBC string
  • I can make the queries I want with pgAdmin III and they work
  • The database server is on the same machine as the "*.jar" application file
  • The jar application works well on a Linux version and another Windows 7 32 bit machine (the development machine)
  • I disabled my antivirus (just in case...)
  • psql.exe works well (I could insert data with it)

Edit 1 -> JJF - I just added postgresql.exe and pg_ctl.exe in the windows firewall, and checked Both checkboxes for each (Public and Home/Work(Private) )

Result: Same Error

Edit2 -> Hardik Patel - Skype is already OFF

Edit 3 -> JJF - After full stop of Windows Firewall, still the same problem

The error I get is this one:

Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections

I wonder if I don't have to "unlock" the postgres account to allow it to access data through JDBC.

Edit 4 - Horse with no name - I replaced localhost by 127.0.0.1 - The port is the standard port 5432, validated with psql - I tested the psql.exe (working) command line before trying the JDBC connection (not working) - Still the same result...

Edit 5 - I am going to put some trace to see if i can get more information

3
Please show the connection string that's produced by your code, not just the code. If it's a dns name, resolve the dns name and make sure it matches what you expect it to resolve to. - Craig Ringer
The error can mean one of the following: 1. Postgres isn't running, 2. Postgres is listening on a different port, 3. The hostname you specified does not resolve properly (try 127.0.0.1 instead to verify that point) - a_horse_with_no_name

3 Answers

0
votes

Turn off skype if running because skype acquires same port. This trick helped me long time ago.

0
votes

Check that Windows firewall is not blocking the port.

0
votes

I corrected my problem by a workaround. I changed the PostgreSQL listen port by 5433 and everything worked like a charm...

I think the original port is used by something else, or blocked by some security tool I could not find.