Failed looking up TXT record for host

Hi all, I’m having a little difficulty connecting to my Atlas database using Java.

this is the driver that i’m importing via Maven


this is the code for the java class

package org.example;

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.ServerApi;
import com.mongodb.ServerApiVersion;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;

public class Main {
    public static void main(String[] args) {
        ConnectionString connectionString = new ConnectionString("mongodb+srv://");
        MongoClientSettings settings = MongoClientSettings.builder()

        MongoClient mongoClient = MongoClients.create(settings);

(I already tried to follow the steps on atlas and also on [View MongoDB Java Driver installation instructions.] but nothing worked.)

When i run the code, this is the error that im getting

Mar 10, 2024, 7:21:12 PM com.mongodb.internal.diagnostics.logging.Loggers shouldUseSLF4J
Warning: SLF4J is not found on the classpath.  Logging is disabled for the 'org.mongodb.driver' component
Exception in thread "main" com.mongodb.MongoConfigurationException: Failed looking up TXT record for host
	at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(
	at com.mongodb.ConnectionString.<init>(
	at com.mongodb.ConnectionString.<init>(
	at org.example.Main.main(
Caused by: com.mongodb.spi.dns.DnsException: DNS error
	at com.mongodb.internal.dns.JndiDnsClient.getResourceRecordData(
	at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(
	... 3 more
Caused by: javax.naming.CommunicationException: DNS error [Root exception is Receive timed out]; remaining name ''
	at com.sun.jndi.dns.DnsClient.query(
	at com.sun.jndi.dns.Resolver.query(
	at com.sun.jndi.dns.DnsContext.c_getAttributes(
	at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(
	at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(
	at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(
	at com.mongodb.internal.dns.JndiDnsClient.getResourceRecordData(
	... 4 more
Caused by: Receive timed out
	at Method)
	at com.sun.jndi.dns.DnsClient.doUdpQuery(
	at com.sun.jndi.dns.DnsClient.query(
	... 11 more

Process finished with exit code 1

and running mongosh this is the error

>mongosh "mongodb+srv://" --apiVersion 1 --username testUser
Enter password: **********
Current Mongosh Log ID: 65ee5db107acbe3496db21bb
Connecting to:          mongodb+srv://<credentials>
Error: queryTxt ETIMEOUT

I already tried with the Java SDK 21, 8, with the diver 5.0.0 and the 4.11.1 and nothing work, Im new on mongo and i like it but this error is driving me crazy.

Quick sanity check:

  1. Did you use the Network feature of Atlas to enable connections from your current IP address?
  2. Is there a typographical error in your mongodb+svr URI?
  3. Can you connect via mongosh or Mongodb Compass?
  4. Are you having firewall issues?

I was able to find out that a ineeded to setup Google’s dns on mi pc to get it work

1 Like

Excellent, good work.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.