java.io.EOFException

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




ramsinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick_72Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
It would help a bit if you could identify in your debug statements *where* the exception has occurred ...
0
CEHJCommented:
>>while(c > 0)

should be

while(c >= 0)
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

CEHJCommented:
Or better

while(c > -1)
0
Giant2Commented:
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
objectsCommented:
                             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
objectsCommented:
do you get the exception everytime you run it?
It could be caused by a network problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.