[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

java.io.EOFException

Posted on 2004-10-28
9
Medium Priority
?
318 Views
Last Modified: 2012-06-21
Hello everybody,

I am executing this Java progam in Linux and trying to retrieve some data from mySQL database which is on the windows machine.It will retrieve if it find new job(row) in the database table.
This is giving following run time error. Can anybody help me how to control this.The exception is as follows.please see below for my code.

===================
Exception ::
===================

Exception is com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1619)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1828)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2179)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:629)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1040)
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:1406)
        at com.mysql.jdbc.Connection.<init>(Connection.java:350)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:218)
        at java.sql.DriverManager.getConnection(DriverManager.java:525)
        at java.sql.DriverManager.getConnection(DriverManager.java:171)
        at DBToLinux.main(DBToLinux.java:21)

=======================

My Java code ::

===========
import java.sql.*;
import java.io.*;

public class DBToLinux
{
         
     public static void main(String args[])
     {    
          while(true)
          {    
             try    
             {          
                         
                    Class.forName("org.gjt.mm.mysql.Driver");
                    Connection con=DriverManager.getConnection("jdbc:mysql://129.217.184.62:3306/Thesiswork","root","");
                    Statement sta=con.createStatement();
                    Statement st1=con.createStatement();
                    Statement st2=con.createStatement();
                   
                    ResultSet rs=sta.executeQuery("select * from submitjobs where Processed=0");
                    //ResultSet rs=sta.executeQuery("Select execute from submitjobs");
                    while(rs.next())
                    {
                         
                         String exe=rs.getString("execute");
                         String Fn=rs.getString("filename");
                         
                         
                         int i=st1.executeUpdate("update submitjobs set Processed=1 where execute='"+exe+"' and filename='"+Fn +"'");
                         System.out.println("File Name is :"+Fn);
                         
                         String del2="delete from submitjobs where  Processed=1";
                         st2.executeUpdate(del2);    
                         
                         try
                          {
                            BufferedWriter out = new BufferedWriter(new FileWriter("PBSJob.txt"));
                            out.write(exe);
                            out.close();
                           
                            // System.exit(1);
                           
                        }
                         catch(EOFException eof1)
                         {
                                     System.out.println("Exception is:" + eof1);
                         }
                         catch (IOException e)
                         {
                             System.out.println("Exception is:"+ e);
                        }
                   
                        //}while(rs.next())
                   
                       
                       
                        //  **** To submit the Job file retrieved from database to PBS ****
                       
                        try
                         {
                              Process p = Runtime.getRuntime().exec("qsub PBSJob.txt");
                              InputStream str = p.getInputStream();
                              StringBuffer buff = new StringBuffer();
                              int c = str.read();
                              while(c > 0)
                              {
                                   buff.append((char)c);
                                   c = str.read();
                              }
                              System.out.println(buff.toString());
                         }
                        catch(EOFException eof1)
                         {
                                System.out.println("Exception is:" + eof1);
                         }
                        catch(IOException e1)
                         {
                             System.out.println("Exception is:"+ e1);
                         }
                       
                             
                         //  **** End of Job submission to PBS ****
                         
                         
                   
               } // while(rs.next())
                   
                   
        }// try
       
        catch(SQLException sql)
        {
                  System.out.println("Exception is "+sql);
        }
       
        catch(NullPointerException ne)
        {
                  System.out.println("Exception is "+ne);
        }
        catch(Exception e)
        {
                   e.printStackTrace();
       }//catch
     

       
       
     } // while for every minute
         
     } // main
     
} // class




0
Comment
Question by:ramsin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 9

Accepted Solution

by:
Nick_72 earned 128 total points
ID: 12432568
you will have to close the resultset:

                        //  **** To submit the Job file retrieved from database to PBS ****
                       
                        try
                         {
                              Process p = Runtime.getRuntime().exec("qsub PBSJob.txt");
                              InputStream str = p.getInputStream();
                              StringBuffer buff = new StringBuffer();
                              int c = str.read();
                              while(c > 0)
                              {
                                   buff.append((char)c);
                                   c = str.read();
                              }
                              System.out.println(buff.toString());
                         }
                        catch(EOFException eof1)
                         {
                                System.out.println("Exception is:" + eof1);
                         }
                        catch(IOException e1)
                         {
                             System.out.println("Exception is:"+ e1);
                         }
                       
                             
                         //  **** End of Job submission to PBS ****
                         
                         
                   
               } // while(rs.next())
               rs.close();  <--------------------- here
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12432577
It would help a bit if you could identify in your debug statements *where* the exception has occurred ...
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 124 total points
ID: 12432632
>>while(c > 0)

should be

while(c >= 0)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 12432640
Or better

while(c > -1)
0
 
LVL 12

Assisted Solution

by:Giant2
Giant2 earned 124 total points
ID: 12433030
put out of the while cycle these lines:
                    Class.forName("org.gjt.mm.mysql.Driver");
                    Connection con=DriverManager.getConnection("jdbc:mysql://129.217.184.62:3306/Thesiswork","root","");
and put them in a try catch block.
you can do the connection only one time.

The code will be like the following:
try{
                    Class.forName("org.gjt.mm.mysql.Driver");
                    Connection con=DriverManager.getConnection("jdbc:mysql://129.217.184.62:3306/Thesiswork","root","");
while(true){
....
}//end while
}catch (Exception ex){System.out.println("ERROR IN THE CONNECTION "+ex);}


The error I see (you post) is about the getConnection method.

Bye, Giant.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 124 total points
ID: 12439849
                             Process p = Runtime.getRuntime().exec("qsub PBSJob.txt");
                              InputStream str = p.getInputStream();
                              StringBuffer buff = new StringBuffer();
                              int c = str.read();
                              while(c > 0)
                              {
                                   buff.append((char)c);
                                   c = str.read();
                              }
                              System.out.println(buff.toString());

instead of that code it is easier to use

                              Process p = Runtime.getRuntime().exec("qsub PBSJob.txt");
                              BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                              StringBuffer buff = new StringBuffer();
                              while (null!=(line=in.readLine()))
                              {
                                 buff.append(line);
                                 buff.append('\n');
                              }
                              System.out.println(buff.toString());

0
 
LVL 92

Expert Comment

by:objects
ID: 12439874
do you get the exception everytime you run it?
It could be caused by a network problem.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question