Unable to connect to remote PostgresSQL server with JDBC driver - postgresql

I'm trying to connect to a remote PostgreSQL database using JDBC, however the connection times out.
To be able to access the remote server I'm connected to a tunnel. There is no problem when I'm trying to connect from the same network with JDBC, only remotely.
I'm able to connect to the database both remotely and locally using other tools (e.g. pgAdmin, HeidiSQL, python sqlalchemy/psycopg2), but not with JDBC. I do not need to add other options for remote connection with the other tools, simply host:port and user/pass.
Searching for solutions I have tried the following without success:
add property "ssl" with value "true" to the driver connection
add property "sslfactory" with value "org.postgresql.ssl.NonValidatingFactory"
add property "loginTimeout" with value 20
set listen_addresses = '*' in postgresql.conf on remote server
add host all all 0.0.0.0/0 md5 to pg_hba.conf on remote server
Using driver version postgresql-42.2.14. I'm attempting to connect using SQuirreL and MATLAB.
As other tools have no issue connecting I'm guessing this is about tweaking the JDBC settings.
What am I missing here?
Edit:
Trying to ping the IP of the remote server (192.168.x.x.) I get:
Reply from 10.x.x.x: Destination net unreachable.
At the same time I'm able to connect to the database on the same server IP. Is this a clue to the problem?
Connection url:
jdbc:postgresql://192.168.x.x:5432/<dbname>
Results of Test-NetConnection
PS > Test-NetConnection 192.168.x.x
WARNING: Ping to 192.168.x.x failed with status:
DestinationNetworkUnreachable
PS > Test-NetConnection 192.168.x.x -port 5432
ComputerName : 192.168.x.x
RemoteAddress : 192.168.x.x
RemotePort : 5432
InterfaceAlias : Local Area Connection 3
SourceAddress : 192.168.x.x
TcpTestSucceeded : True
Running tracert 192.168.x.x
Tracing route to 192.168.x.x over a maximum of 30 hops
1 <1 ms <1 ms <1 ms 192.168.0.1
2 10.x.x.x reports: Destination net unreachable.
Trace complete.
Stacktrace (SQuirreL):
java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.postgresql.core.PGStream.<init>(PGStream.java:81)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:93)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:217)
at org.postgresql.Driver.makeConnection(Driver.java:458)
at org.postgresql.Driver.connect(Driver.java:260)
at net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(SQLDriverManager.java:147)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:136)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.lambda$execute$0(OpenConnectionCommand.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

You are pinging IP address in the range of 192.168.x.x and getting reply from 10.x.x.x. Those are two different sub-nets.
As odd as it seems, it does not go well with your initial statement about being able to connect via other means. If network was issue then other tools would have failed as well. Not getting a reply for ping "Request time out" is expected result if there is blockage.
"Destination unreachable" means there is no proper route available to the IP you are trying to get to. With that issue, no other connections to that host should be reachable from your host.
Please confirm if all connections you attempted were from same client host. Also have you tried ODBC connector to see if that works? That allows System DSNs and you do not need to do much in attempt to connect.
Please make sure you do tests either from same hosts or two machines on same network to simplify things.
With "Destination unreachable" error your client should not be talking to server in anyway if same destination IP is used.

Related

Talend Error Exception in component tPOP_1 (test) javax.mail.MessagingException: Connection timed out: connect;

Please help me to find the solution for below error. i have tried using imap and pop3 setting, below are the configuration settings i have used
pop3:
Server name: outlook.office365.com
Port: 995
imap:
Server name: outlook.office365.com
Port: 993
Error im getting:
Exception in component tPOP_1 (test)
javax.mail.MessagingException: Connection timed out: connect;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at accor.test_0_1.test.tPOP_1Process(test.java:769)
at accor.test_0_1.test.runJobInTOS(test.java:4959)
at accor.test_0_1.test.main(test.java:4727)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
[FATAL]: accor.test_0_1.test - tPOP_1 Connection timed out: connect
Attached is the tpop component settings i have used.
tpop component settings
configuration settings i have used
pop3:
Server name: outlook.office365.com
Port: 995
imap:
Server name: outlook.office365.com
Port: 993
Try to add this Java option in job jvm Parameters and try :
-Dmail.imap.auth.plain.disable=true
Link could help :
https://confluence.atlassian.com/jirakb/imap-setup-fails-with-authenticate-failed-error-in-logs-in-jira-server-185401609.html
Your component configuration is correct so if it doesn't work within these options that means that your organisation does bloc something
Microsoft disabled Basic Auth. You won't be able to connect, unless you use OAuth token.
Talend 8 / 7.3 R2022-09 release introduced Microsoft Exchange Auth to tPOP that automatically exchanges the credentials. Configuration for that can be found in the official help document: https://help.talend.com/r/en-US/8.0/pop/configuring-an-oauth2-application-for-pop-and-imap
There's also a long answer on Talend community with all the details: https://community.talend.com/s/question/0D55b00007LRyrWCAT/tpop-microsoft-basic-authentication-retirement?language=en_US
Git repository for the component: https://github.com/Talend/tdi-studio-se/tree/master/main/plugins/org.talend.designer.components.localprovider/components/tPOP

connect spring boot app to mongodb

i'm trying to connect my spring boot app to a remote mongodb database.
When i run my app i got this error:
2017-05-25 15:22:57.829 INFO 4532 --- [*******:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server mongodb-server-address:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongodb-driver-core-3.4.2.jar:na]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_79]
Caused by: java.net.ConnectException: Connection refused: connect
By default MongoDB only binds to the loopback interface which makes it only accessible from localhost. To change that you need to edit this line in mongod.conf file;
you can change it to allow LAN and local connections or you can remove or comment out that line bind_ip = 127.0.0.1 to allow all connections.
For more info : MongoDB – Allow remote access

Unable to connect to "Compose for PostgreSQL" DB created in bluemix through eclipse

I am not able to establish connection to Compose for PostgreSQL DB service using eclipse. Getting below error while Testing the connection.
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:122)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
at org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connection.java:116)
at org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3.Jdbc3Connection.(Jdbc3Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:369)
at org.postgresql.Driver.connect(Driver.java:245)
at org.eclipse.datatools.enablement.internal.postgresql.PostgreSQLJDBCConnection.createConnection(PostgreSQLJDBCConnection.java:87)
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
at org.eclipse.datatools.enablement.internal.postgresql.PostgreSQLJDBCConnection.(PostgreSQLJDBCConnection.java:47)
at org.eclipse.datatools.enablement.internal.postgresql.PostgreSQLConnectionFactory.createConnection(PostgreSQLConnectionFactory.java:51)
at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
I am able to connect to the DB through the application deployed in BlueMix.
How are you populating the connection credentials? The application will have access the VCAP_SERVICES when run on Bluemix, but unless you have specifically copied that environment variable to your Eclipse environment, that information will not be available to your application.
The error indicates that the connection was refused. This most likely means that the host and port combination you've entered is incorrect. You'll want to ensure that you can connect to the host.
You can check that your local system can connect by doing nc -vz xxxxx.dblayer.com 10000 where xxxxx.dblayer.com is the full hostname provided to you within the variable and 10000 is the port, also provided.
It seems as though your syntax/configuration may not be correct as a connection being refused would indicate that it cannot connect however it's not clear from your post what hostname/port it's actually trying to connect to.

Error while attempting to connect to an Oracle 12c database using eclipse

I am trying to connect to an oracle 12c database using the eclipse IDE but I get the error "Ping Failed!" every time I try to test the connection. I have tried to disable the windows firewall as some other similar post suggested it might be network related or the fire wall blocking it. I have the following settings:
SID: XE
Host: localhost
Port Number: 1521
UserName: myusername
Password: mypassword
connection URL: jdbc:oracle:thin:#localhost:1521:XE
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:328)
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:96)
at org.eclipse.datatools.enablement.internal.oracle.JDBCOracleConnectionFactory.createConnection(JDBCOracleConnectionFactory.java:27)
at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:470)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:506)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:595)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:230)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496)
... 13 more
Caused by: java.net.UnknownHostException: server
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:120)
at oracle.net.nt.ConnOption.connect(ConnOption.java:159)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:428)
... 18 more
Any ideas of what I am doing wrong?
Change your connection url to jdbc:oracle:thin:#server:1521:db. This will work.

java.net.BindException: Address already in use: JVM_Bind [duplicate]

This question already has answers here:
java.net.BindException: Address already in use: JVM_Bind
(2 answers)
Closed 6 years ago.
i having this problem in eclipse
I m running a simple project and following error appears:
SEVERE: StandardServer.await: create[8005]:
java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:373)
at org.apache.catalina.startup.Catalina.await(Catalina.java:647)
at org.apache.catalina.startup.Catalina.start(Catalina.java:607)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
after this a dialog box appears showing "Server Tomcat v6.0 Server at localhost failed to start." I have searched and tried all options answered here and nothing work for me. I also searched ports and change the tomcat port but nothing helps.? what should i do?
First i was getting the error "Several ports (8080, 8009) required by Tomcat v6.0 Server at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s)."
after changing port,i am getting "Server Tomcat v6.0 Server at localhost failed to start" error..
The errormessage sounds very clear - that port (8005) is already in use. Are you running two instances of tomcat in parallel? Maybe one from command line and one from eclipse?
Issue is because of 8005 port is using by some other application.
so change the port number in eclipse by
Double click on Apache Tomcat Server in server tab and open the server in eclipse
expand port panel
change HTTP/1.1, tomcat admin port and AJP/1.3(check used port by typing netstat -an in cmd)
save it
try again