# Caused by: java.net.SocketTimeoutException: Connect timed out

**URL:** <https://forum.yugabyte.com/t/caused-by-java-net-sockettimeoutexception-connect-timed-out/2134>\
**Category:** General\
**Created:** [June 8, 2023, 9:09am UTC](https://forum.yugabyte.com/t/caused-by-java-net-sockettimeoutexception-connect-timed-out/2134 "2023-06-08T09:09:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mayunish](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Mayunish](https://forum.yugabyte.com/u/Mayunish)\
**Post date:** [June 8, 2023, 9:09am UTC](https://forum.yugabyte.com/t/caused-by-java-net-sockettimeoutexception-connect-timed-out/2134/1 "2023-06-08T09:09:01Z")

</div>

I used Docker compose to create a 3 node cluster(n1,n2,n3) with replication factor 3 with one master (yb-master). I am able to access the sql query layer of these nodes through the terminal but I am not able to figure out correct url to connect to these nodes using jdbc.  
“jdbc:postgresql://172.18.0.5:5433/yugabyte?user=yugabyte&password=yugabyte&ssl=true&sslmode=verify-full&sslrootcert=~/.postgresql/root.crt”  
This is the url I am using where 172.18.0.5 is the ip address for my n1 node.

---

<div class="post-metadata">

**Author:** ![FranckPachot](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/franckpachot/32/353_2.png) [@FranckPachot](https://forum.yugabyte.com/u/FranckPachot)\
**Post date:** [June 8, 2023, 10:00am UTC](https://forum.yugabyte.com/t/caused-by-java-net-sockettimeoutexception-connect-timed-out/2134/2 "2023-06-08T10:00:33Z")

</div>

> [@Mayunish](#):
>
> 172.18.0.5 is the ip address for

Hi Mayunish, this address works only within the docker-compose network. If you run the java application in the same docker-compose, this should work, but not sure if you have the right certificate. CAn you share the error message? If you access from outside of the docker network, you should use port redirection.

---

<div class="post-metadata">

**Author:** ![Mayunish](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Mayunish](https://forum.yugabyte.com/u/Mayunish)\
**Post date:** [June 8, 2023, 10:15am UTC](https://forum.yugabyte.com/t/caused-by-java-net-sockettimeoutexception-connect-timed-out/2134/3 "2023-06-08T10:15:01Z")

</div>

org.postgresql.util.PSQLException: The connection attempt failed.  
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:331)  
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)  
at org.postgresql.jdbc.PgConnection.(PgConnection.java:223)  
at org.postgresql.Driver.makeConnection(Driver.java:402)  
at org.postgresql.Driver.connect(Driver.java:261)  
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)  
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:252)  
at org.example.usersTableWrite.main(usersTableWrite.java:8)  
Caused by: java.net.SocketTimeoutException: Connect timed out  
at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546)  
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597)  
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)  
at java.base/java.net.Socket.connect(Socket.java:633)  
at org.postgresql.core.PGStream.createSocket(PGStream.java:241)  
at org.postgresql.core.PGStream.(PGStream.java:98)  
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:109)  
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235)  
… 7 more  
This is my error message. Also, can you help me with how to use port redirection if it is needed here.

---

<div class="post-metadata">

**Author:** ![FranckPachot](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/franckpachot/32/353_2.png) [@FranckPachot](https://forum.yugabyte.com/u/FranckPachot)\
**Post date:** [June 8, 2023, 10:48am UTC](https://forum.yugabyte.com/t/caused-by-java-net-sockettimeoutexception-connect-timed-out/2134/4 "2023-06-08T10:48:05Z")

</div>

To tunnel the port, here is an example: [https://github.com/FranckPachot/ybdemo/blob/main/docker/yb-lab/example-docker-compose-rf3.yaml#L164](https://github.com/FranckPachot/ybdemo/blob/main/docker/yb-lab/example-docker-compose-rf3.yaml#L164)  
This forwards the port 5433 within the container to the 5433 on my laptop where I run docker. And then I can connect with jdbc:postgresql://localhost:5433/yugabyte
