The error is as follows:
Org. PostgreSQL. util. psqlexception: the connection is rejected. Check the host name and port number and make sure that the postmaster can accept the TCP/IP connection. At Org. postgreSQL. core. v3.connectionfactoryimpl. openconnectionimpl (connectionfactoryimpl. java: 136) at Org. postgreSQL. core. connectionfactory. openconnection (connectionfactory. java: 64) at Org. postgreSQL. jdbc2.abstractjdbc2connection. <init> (abstractjdbc2connection. java: 123) at Org. postgreSQL. jdbc3.abstractjdbc3connection. <init> (abstractjdbc3connection. java: 28) at Org. postgreSQL. jdbc3g. abstractjdbc3gconnection. <init> (abstractjdbc3gconnection. java: 20) at Org. postgreSQL. jdbc3g. jdbc3gconnection. <init> (jdbc3gconnection. java: 22) at Org. postgreSQL. driver. makeconnection (driver. java: 391) at Org. postgreSQL. driver. connect (driver. java: 265) at com. mchange. v2.c3p0. drivermanagerdatasource. getconnection (drivermanagerdatasource. java: 68) at com. mchange. v2.c3p0. wrapperconnectionpooldatasource. getpooledconnection (wrapperconnectionpooldatasource. java: 87) at com. mchange. v2.c3p0. impl. c3p0pooledconnectionpool $1. acquireresource (c3p0pooledconnectionpool. java: 83) at com. mchange. v2.resourcepool. basicresourcepool. assimilateresource (basicresourcepool. java: 884) at com. mchange. v2.resourcepool. basicresourcepool. acquireuntil (basicresourcepool. java: 601) at com. mchange. v2.resourcepool. basicresourcepool. access $400 (basicresourcepool. java: 31) at com. mchange. v2.resourcepool. basicresourcepool $ acquiretask. run (basicresourcepool. java: 1079) at com. mchange. v2.async. threadpoolasynchronousrunner $ poolthread. run (threadpoolasynchronousrunner. java: 354) caused by: java.net. connectexception: Connection timed out: connectat java.net. plainsocketimpl. socketconnect (native method) at java.net. plainsocketimpl. doconnect (unknown source) at java.net. plainsocketimpl. connecttoaddress (unknown source) at java.net. plainsocketimpl. connect (unknown source) at java.net. sockssocketimpl. connect (unknown source) at java.net. socket. connect (unknown source) at java.net. socket. connect (unknown source) at java.net. socket. <init> (unknown source) at java.net. socket. <init> (unknown source) at Org. postgreSQL. core. pgstream. <init> (pgstream. java: 60) at Org. postgreSQL. core. v3.connectionfactoryimpl. openconnectionimpl (connectionfactoryimpl. java: 74 )... 15 more
Solution:
1. The connection to PostgreSQL is rejected. Check the host name and port number and confirm that the postmaster can accept the TCP/IP connection.
This error often occurs when you connect to a PostgreSQL database using JDBC (or the database connection tool provided by ECLIPSE). However, you can use pgadmin III to correctly connect to the database, indicating that the user name and password are correct.
This is mainly caused by the user password authentication method. After the PostgreSQL database is installed, the MD5 password encryption authentication method is used by default.
2. This problem also occurs when the database is connected to another machine.
Solution:
! Open the data folder under the PostgreSQL installation directory, find the pg_cmd.conf file, and open
Under the # type Database User CIDR-ADDRESS method:
Add the following sentence:
Host All all 0.0.0.0/0 MD5
2. Change PostgreSQL. conf
# Listen_addresses = 'localhost' # What IP address (es) to listen on;
Is
Listen_addresses = '*' # What IP address (es) to listen on;
Remember to remove the # Before listen_addresses.