• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Postgresql, JDBC and Virtual Machine

 
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic