Avatar of Billy Ma
Billy MaFlag for Hong Kong asked on

Error Message in my Java Program

I don't know why I get the following error message when I run my Java program. In the Code Snippet, this is the function that I modified yesterday.

Cannot open Connection
The driver was unable to create a connection due to an inability to establish th
e client portion of a socket.

This is usually caused by a limit on the number of sockets imposed by the operat
ing system. This limit is usually configurable.

For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel o
r system reconfiguration may also be required.

For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q19627
public void fetch_device_data(String device_name){
        String s = null;
		String line = "";
        try {
				FileOutputStream output_file = new FileOutputStream("output.txt");
				FileOutputStream error_file = new FileOutputStream("error.txt");
	            Process p = Runtime.getRuntime().exec("wget -O source_data/" + device_name + ".html http://****:****@"+device_name);
				StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT", output_file);
				StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR", error_file);	
				int exitVal = p.waitFor();
	            System.out.println("ExitValue: " + exitVal);
			}catch(Throwable t){
			BufferedReader stdInput = new BufferedReader(new FileReader("source_data/" + device_name + ".html"));
			boolean inside_table_tag = false;
            while ((s = stdInput.readLine()) != null) {
				/* If encounter a table tag */
					if(inside_table_tag == true){
						inside_table_tag = false;
						line = line.replaceAll("<(tr|td)[^>]*>", "<$1>");		//Remove all the attributes in tr and td tags
						line = line.replaceAll("<([/]{0,1}[a-z]*)>[ ]*", "<$1>").trim();
						line = line.replaceAll("</(td|tr)>", "");				//Remove all ending tr and td tags
						line = line.replaceFirst("<td>", "");
						String data[] = line.split("<td>");
					}else if(inside_table_tag == false){
						inside_table_tag = true;
						line = "";
				/* If on a td line */
				if(inside_table_tag && s.contains("<td")){
					line += s + " ";
        catch (IOException e) {
            write_log("exception happened - here's what I know: ");
**** Code Edited for content 5-23-8 MM ****

Open in new window


Avatar of undefined
Last Comment
Mick Barry

8/22/2022 - Mon
Billy Ma

Is it because the database connection did not close?
Mick Barry

for one you're not closing the file.
but why are you writing it to a file and then reading the file back?
And why use wget?

Billy Ma

wget is a program to get the HTML source from a web page and write it into a file.

then I use my program to read the .html file and then process it.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Mick Barry

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Billy Ma

hey........because the webpage have .htaccess, is URLConnection able to pass through the .htaccess?
Billy Ma

Please DELETE this question for me please because the source code contains the password...
Mick Barry

> hey........because the webpage have .htaccess, is URLConnection able to pass through the .htaccess?

yes, though I prefere httpclient as its more powerful.

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Billy Ma

is httpclient able to run under both Linux and Windows?
Mick Barry

yes, its a java library