• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Postgresql, JDBC and Virtual Machine

 
Daisy Smith
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I would like to connect to postgresql on a virtual machine using JDBC. Here is part of the code:
Code:
Here is the output when the code is run:

I think the problem comes from the connection parameters. I think it is trying to connect to postgresql on my local machine on not on the VM.
I need help in getting the right parameters to connect to postgresql on the VM.

Thanks
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not a virtual machine expert at all, but would it not have a different IP-address than localhost? Because localhost refers to your computer, not the virtual machine
 
Claude Moore
Ranch Hand
Posts: 828
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides of Roel's answer, remember that you need to configure Postgresql to accept connection not from localhost - please check documentation.
By the way, Roel is right about IP address of virtual machines, they need to have a specific IP address to be accessed. You may have to review networking settings of both your PC and virtual machine to make them in same LAN - I just remember having some troubles with bridged networking times ago.
 
Daisy Smith
Greenhorn
Posts: 27
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your replies.

I was just about the post again when I found the solution. I had changed the url to include the VM's IP and port number.
Also I had enabled TCP/IP connections in postgresql.conf by changing #listen_addresses = 'localhost' to listen_addresses = '*' .
However, the trick was to change the pg_hba.conf file. There was no indication of how the IP address would connect. All IPv4 connections had the format 127.0.0.1/32.
So I added the line host: all all 192.168.0.0/16 md5

The code works now.

Thank you.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for coming back and sharing the solution. That will be very helpful for other ranchers having similar issues. Have a cow!
 
Daisy Smith
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic