Buras
Buras

Reputation: 3099

How to overcome Unknown Host Exception with no access to system32\drivers\etc\hosts

I tried to use the following connection

URL oracle = new URL("http://www.oracle.com/");
    URLConnection yc = oracle.openConnection(); 
    yc.setConnectTimeout(100000);
    BufferedReader in = new BufferedReader(new InputStreamReader(
                                yc.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null) 
        System.out.println(inputLine);
    in.close();

It throws java.net.UnknownHostException

I cannot set mapping in system32\drivers\etc\hosts . And I cannot make any changes there . Is there any way to overcome this ? It works on my other computer, but does not on the one want to use it on


i tried using

searchUrl="http://96.7.228.140/";

And got the following error

java.net.ConnectException: Connection timed out: connect

Upvotes: 2

Views: 1010

Answers (1)

Alexandre Santos
Alexandre Santos

Reputation: 8338

You already tried substituting the domain name with the IP in the URL and it didn't work. That indicates there's a different problem. Most likely not a java problem. You shouldn't try to fix it using the hosts file.

If you can ping oracle.com then Java should be able to connect to it.

The only issue could be on the length of the connection, as your connection might be timing out if your network is too slow.

Do a ping on oracle.com and check what is the time it takes for them to respond. Adjust your connection timeout accordingly.

If that doesn't work, you might have a firewall problem in the other computer. Either that or your network adapter is not properly installed.

Can you open an internet browser on the machine and navigate to http://www.oracle.com?

If you can, then try your program. If it doesn't work then check the connection time.

Upvotes: 1

Related Questions