Reputation: 432
I have a remote MongoDB that I need to connect to. I have all the credentials, but when trying to connect from gradle with this.mongoClient = MongoClients.create(dbConnectionString);
, I get following error:
java.io.UncheckedIOException: java.net.SocketException: Network is unreachable
at java.base/sun.nio.ch.DatagramSocketAdaptor.disconnect(DatagramSocketAdaptor.java:136)
at java.base/java.net.DatagramSocket.disconnect(DatagramSocket.java:393)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:437)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:214)
at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171)
at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(DefaultDnsResolver.java:114)
at com.mongodb.ConnectionString.<init>(ConnectionString.java:381)
at com.mongodb.client.MongoClients.create(MongoClients.java:61)
at io.my.package.dbsetup.DatabaseService.<init>(DatabaseService.java:28)
When I print the connectionString
and run mongo $connectionString
in terminal, I can connect with no problems. Even MongoDB Compass works. It's just Gradle that doesn't.
My colleague with Ubuntu (I have a Mac) can connect with no issues when running the same code. What could be causing this? Firewall is off.
Upvotes: 1
Views: 460
Reputation: 432
Turns out I needed to use different Java version - 16 didn't work, but I had luck with 8
Upvotes: 1