Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.net.SocketTimeoutException: Read timed out error when trying to read from table

I'm working on coding a program that will go and retrieve the price of a person from a table on a website. The code gets a last name and searches the table for that name before returning the price (a different column) whenever I run it I get a java.net.SocketTimeoutException: Read timed out

This is the code I'm using to query the website

public String price(String lastName) throws IOException
{
    Document doc = Jsoup.connect(url).get();

    Elements rows = doc.getElementsByTag("tr");;

    for(Element row : rows)
    {
        Elements columns = row.getElementsByTag("td");
        String lastName = columns.get(0).text();
        String price = columns.get(2).text();
        if(lastName.equalsIgnoreCase(name))
        {
            return price;
        }
    }
    return null;
}
like image 816
AndyReifman Avatar asked Mar 13 '14 00:03

AndyReifman


People also ask

How do I fix Java net SocketTimeoutException read timed out?

A possible solution for this problem within the Tomcat web application is to modify the CONTEXT. XML file, and modify the CONNECTOR definition that governs the workstation browser connectivity to the Tomcat server. Specifically, modify the connectionTimeout value. Increase this value to suppress the error condition.

What causes Java SocketTimeoutException?

As you may suspect based on the name, the SocketTimeoutException is thrown when a timeout occurs during a read or acceptance message within a socket connection. Throughout this article we'll explore the SocketTimeoutException in more detail, starting with where it resides in the overall Java Exception Hierarchy.

What is read timed out error?

From the client side, the “read timed out” error happens if the server is taking longer to respond and send information. This could be due to a slow internet connection, or the host could be offline. From the server side, it happens when the server takes a long time to read data compared to the preset timeout.


1 Answers

Try this:

Jsoup.connect(url).timeout(60*1000).get(); 

or...

Jsoup.connect(url).timeout(0).get();
like image 83
martynas Avatar answered Nov 15 '22 07:11

martynas