0

i want to add database to my netbeans java project using ip address.
my question is that when i specify hostname by name that is "localhost" followed my correct details in the new connection wizard in netbeans connection establishes succesfully. this is as shown below.host by name

but when i specify host by specifying ip address of my own computer that is localhost connection doesn't get established. same is shown belowipconfig host my ip

well my motive is not to put ip of localhost but of another pc for remote database sharing over internet. but i think the problem lies in the method of specifying host using ip. if i get it right database sharing might work between different hosts as well.
also any other methods of sharing postgres database over the internet are also welcome.
i am a newbie in java as well as netbeans so any help is appreciated.

6
  • There's no way I can read any of those screen grabs. Can you edit them so just the relevant text is visible. Although looking and the sub-pixel text, it doesn't appear to be "127.0.0.1" so try that for your IP address. Commented Jul 17, 2014 at 6:20
  • @user2338547 well i have updated the screen and the ip address is same as that shows in ipconfig command as shown Commented Jul 17, 2014 at 6:34
  • What is the value of listen_address in postgresql.conf? Commented Jul 17, 2014 at 6:35
  • And does your firewall allow connections to your IP address? Can you ping that IP address? This is more of a network configuration problem than anything, although verifying your postgres config too as mentioned above is also necessary. Commented Jul 17, 2014 at 6:47
  • @a_horse_with_no_name value of listen_address in postgresql.conf is * which i changed to my system's ip address. will that help. Commented Jul 17, 2014 at 7:46

2 Answers 2

1

Your sense of thinking that localhost is your IP-Address is itself wrong!You need to have a loop-back address which will direct your operations to itself and not as the case of your IP-Address shown in ipconfig command.

You need to specify this 127.0.0.1 as the IP-Address. 127.0.0.1 is the most-commonly used IPv4 loopback address.

Try this :- jdbc:postgresql://127.0.0.1:5432/nic_project_db

localhost means this computer. It is a hostname that the computer's software and users may employ to access the computer's own network services via its loopback network interface. Using the loopback interface bypasses local network interface hardware. // Taken from Wikipedia.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for help it worked but my motive is to connect database to another host over internet how would i do that if keep on using a standard loopback addrress?
Well,if you want to connect on a remote machine having a different IP,you simply provide his IP-Address and the port number which can connect you with his database(PostgreSQL here).Probably,the default is what you mentioned---5432,but change it to the default!
tried that a zillion times but always get some error like "Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."
1

For future reference to anyone that might have same question here is solution:

In the postgresql database folder open up the postgresql.conf file. Add the following line:

listen_addresses = '*'

Then open up the pg_hba.conf file and add the following line:

host    all             all             0.0.0.0/0               md5

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.