I/O Exception Java Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SamirM
    New Member
    • Apr 2006
    • 1

    I/O Exception Java Error

    i am new to java. i am having trouble running some of my codes. Can someone tell me why i am getting "I/O Exception while Reading, Connection refused", message.?
  • jagannathan
    New Member
    • Jul 2006
    • 11

    #2
    please send the code where u get this error

    Comment

    • mahammadseeraz
      New Member
      • Jul 2007
      • 6

      #3
      Originally posted by SamirM
      i am new to java. i am having trouble running some of my codes. Can someone tell me why i am getting "I/O Exception while Reading, Connection refused", message.?
      U might have these problems
      1. didn't throw IOException
      2. Import IO package.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by mahammadseeraz
        U might have these problems
        1. didn't throw IOException
        2. Import IO package.
        No. The OP doesn't have any of those problems.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          A 'connection refused' exception indicates that there's no server responding at all.
          Firewalls? Is the server running? Correct IP address? Correct port number?

          kind regards,

          Jos

          Comment

          • andhraprince
            New Member
            • Aug 2010
            • 1

            #6
            I/O Exception while reading

            [B]Hi
            Every1
            I have coded a applet program named Friends.java, long years ago (may be 5 years) and i made it out without any exceptions and i save the file in a CD. But now when i execute the program i don't get any Exceptions but when i execute appletviewer command i'm getting error message as:- "I/O Exception while reading: F:\Friends.html (The system cannot find the specified file)

            The following is the file, some1 please execute the following program on their respective JVM's and let me know please

            //import java.io.*;
            import javax.swing.*;
            import java.awt.*;
            import java.awt.event. *;
            //import java.util.*;
            //import java.sql.*;
            public class Friends extends JFrame implements ActionListener, MouseListener
            {
            JFrame frame;
            JPanel main,card,p1,p2 ;

            static PreparedStateme nt stat,stat1,stat 2;
            static Connection con,conn,connn;
            static ResultSet result;
            JOptionPane pobj;

            JLabel l,l1,l2,l3,l4,l 5,l6,l7;
            TextField t,t1,t2,t3,t6,t 7;
            TextArea ta;
            Choice cities;
            JButton enter,add,del,q uery,update,exi t,truncate;
            FlowLayout fl;
            CardLayout cl;
            GridBagLayout gbl,gbl2,gbl3;
            GridBagConstrai nts gbc,gbc2,gbc3;
            Thread th;
            //Date date;
            GregorianCalend ar calendar;
            String strDate,strTime ,strStatus;

            public Friends()
            {
            frame=new JFrame(" Friends Contact Numbers and their Birthday Dates ");
            frame.setSize(5 00,500);
            frame.setVisibl e(true);
            frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
            main=new JPanel();
            card=new JPanel();
            frame.getConten tPane().add(mai n);

            gbc=new GridBagConstrai nts();
            gbc2=new GridBagConstrai nts();
            gbc3=new GridBagConstrai nts();
            gbl=new GridBagLayout() ;
            gbl2=new GridBagLayout() ;
            gbl3=new GridBagLayout() ;
            cl=new CardLayout();

            main.setLayout( gbl);
            card.setLayout( cl);

            gbc.anchor=Grid BagConstraints. CENTER;
            gbc.gridx=1;
            gbc.gridy=2;
            gbl.setConstrai nts(card,gbc);
            main.add(card);
            main.setBackgro und(Color.pink) ;

            Font font =new Font("Times New Roman" ,Font.BOLD,12);
            JOptionPane pobj=new JOptionPane();

            l=new JLabel("Enter Access Code");
            l.setForeground (Color.blue);
            t=new TextField(10);
            t.setEchoChar(' *');

            l1=new JLabel("Friend Name");
            l2=new JLabel("Cell Number");
            l3=new JLabel("LandLin e");
            l4=new JLabel("Address ");
            l5=new JLabel("City");

            cities=new Choice();
            //cities.setBackg round(Color.yel low);
            cities.setFont( font);
            cities.addItem( "----------Select----------");
            cities.addItem( "Hyderabad" );
            cities.addItem( "Bangalore" );
            cities.addItem( "Guntakal") ;
            cities.addItem( "Chattisgar d");

            t1=new TextField(17);
            t1.setFont(font );
            t1.setForegroun d(Color.blue);
            //t1.setBackgroun d(Color.yellow) ;
            t2=new TextField(17);
            t2.setFont(font );
            //t2.setBackgroun d(Color.yellow) ;
            t3=new TextField(17);
            t3.setFont(font );
            t3.setForegroun d(Color.blue);
            //t3.setBackgroun d(Color.yellow) ;
            ta=new TextArea(3,17);
            ta.setFont(font );
            ta.setForegroun d(Color.blue);
            //ta.setBackgroun d(Color.yellow) ;
            l6=new JLabel("E - mail ");
            t6=new TextField(17);
            t6.setFont(font );
            //t6.setBackgroun d(Color.yellow) ;
            l7=new JLabel("Birthda y");
            t7=new TextField(17);
            t7.setFont(font );
            //t7.setBackgroun d(Color.yellow) ;
            add=new JButton("Insert ");
            del=new JButton("Delete ");
            query =new JButton ("Query");
            update=new JButton("Update ");
            exit=new JButton("Exit") ;
            enter=new JButton("Enter" );
            truncate=new JButton("Trunca te");

            p1=new JPanel();
            p1.setLayout(gb l2);
            p1.setBackgroun d(Color.cyan);

            gbc2.anchor=Gri dBagConstraints .CENTER;
            gbc2.gridx=1;
            gbc2.gridy=1;
            gbl2.setConstra ints(l,gbc2);
            p1.add(l);
            gbc2.anchor=Gri dBagConstraints .CENTER;
            gbc2.gridx=2;
            gbc2.gridy=1;
            gbl2.setConstra ints(t,gbc2);
            p1.add(t);
            gbc2.anchor=Gri dBagConstraints .CENTER;
            gbc2.gridx=2;
            gbc2.gridy=2;
            gbl2.setConstra ints(enter,gbc2 );
            p1.add(enter);
            enter.addAction Listener(this);
            //enter.addMouseL istener(this);
            enter.setToolTi pText("Enter the required code in the Text Box and Click this button to go to the next page");

            p2=new JPanel();
            p2.setLayout(gb l3);
            p2.setBackgroun d(Color.cyan);

            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=5;
            gbc3.gridy=1;
            gbl3.setConstra ints(truncate,g bc3);
            p2.add(truncate );
            truncate.setFon t(font);
            truncate.setToo lTipText("Click this button to Truncate the data in the Database");
            truncate.addAct ionListener(thi s);


            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=1;
            gbc3.gridy=1;
            gbl3.setConstra ints(l1,gbc3);
            p2.add(l1);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=2;
            gbc3.gridy=1;
            gbl3.setConstra ints(t1,gbc3);
            p2.add(t1);

            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=1;
            gbc3.gridy=2;
            gbl3.setConstra ints(l2,gbc3);
            p2.add(l2);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=2;
            gbc3.gridy=2;
            gbl3.setConstra ints(t2,gbc3);
            p2.add(t2);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=1;
            gbc3.gridy=3;
            gbl3.setConstra ints(l3,gbc3);
            p2.add(l3);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=2;
            gbc3.gridy=3;
            gbl3.setConstra ints(t3,gbc3);
            p2.add(t3);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=1;
            gbc3.gridy=4;
            gbl3.setConstra ints(l4,gbc3);
            p2.add(l4);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=2;
            gbc3.gridy=4;
            gbl3.setConstra ints(ta,gbc3);
            p2.add(ta);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=1;
            gbc3.gridy=5;
            gbl3.setConstra ints(l5,gbc3);
            p2.add(l5);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=2;
            gbc3.gridy=5;
            gbl3.setConstra ints(cities,gbc 3);
            p2.add(cities);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=1;
            gbc3.gridy=6;
            gbl3.setConstra ints(l6,gbc3);
            p2.add(l6);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=2;
            gbc3.gridy=6;
            gbl3.setConstra ints(t6,gbc3);
            p2.add(t6);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=1;
            gbc3.gridy=7;
            gbl3.setConstra ints(l7,gbc3);
            p2.add(l7);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=2;
            gbc3.gridy=7;
            gbl3.setConstra ints(t7,gbc3);
            p2.add(t7);

            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=1;
            gbc3.gridy=8;
            gbl3.setConstra ints(add,gbc3);
            p2.add(add);
            add.setFont(fon t);
            add.setToolTipT ext("Click this button to Add the details you have entered to the Database");
            add.addActionLi stener(this);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=2;
            gbc3.gridy=8;
            gbl3.setConstra ints(del,gbc3);
            p2.add(del);
            del.setFont(fon t);
            del.setToolTipT ext("Click this button to Delete the details you have entered to the Database");
            del.addActionLi stener(this);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=3;
            gbc3.gridy=8;
            gbl3.setConstra ints(query,gbc3 );
            p2.add(query);
            query.setFont(f ont);
            query.setToolTi pText("Click this button to View the details of your Friends that you have entered in the Database");
            query.addAction Listener(this);
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=4;
            gbc3.gridy=8;
            gbl3.setConstra ints(update,gbc 3);
            p2.add(update);
            update.setFont( font);
            update.setToolT ipText("Click this button to Update the details of your Friends that you have entered in the Database");
            update.addActio nListener(this) ;
            gbc3.anchor=Gri dBagConstraints .CENTER;
            gbc3.gridx=5;
            gbc3.gridy=8;
            gbl3.setConstra ints(exit,gbc3) ;
            p2.add(exit);
            exit.setFont(fo nt);
            exit.setToolTip Text("Click this button to Exit ");
            exit.addActionL istener(this);

            //th=new Thread(this);
            //th.start();

            card.add(p1,"Pa nel1");
            card.add(p2,"Pa nel2");
            }
            public void mousePressed(Mo useEvent me)
            {
            cl.next(card);
            }
            public void mouseClicked(Mo useEvent me)
            { }
            public void mouseEntered(Mo useEvent me)
            { }
            public void mouseExited(Mou seEvent me)
            { }
            public void mouseReleased(M ouseEvent me)
            { }

            public static void main(String args[])
            {
            Friends friends=new Friends();
            try
            {
            Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
            con=DriverManag er.getConnectio n("jdbc:odbc:Fr iends","sa","jy otshna");
            stat1=con.prepa reStatement("Se lect * from Friends where Name = ?");
            }
            catch(Exception e)
            {
            System.out.prin tln("Could not execute the query " + e);
            }
            }
            /*public void run()
            {
            while(th!=null)
            {
            disp();
            try
            {
            th.sleep(1000);
            }
            catch(Interrupt edException e)
            {
            getAppletContex t().showStatus( "Thread Interrupted");
            }
            }
            }
            public void disp()
            {
            date=new Date();
            calendar=new GregorianCalend ar();
            calendar.setTim e(date);
            strTime=calenda r.get(Calendar. HOUR)+ ":" +(calendar.get( Calendar.MINUTE )) +":"+(calendar. get(Calendar.SE COND));
            strDate=(calend ar.get(Calendar .MONTH)+1)+ ":" +calendar.get(C alendar.DATE)+" :"+calendar.get (Calendar.YEAR) ;
            strStatus=strTi me+ " " +strDate;
            getAppletContex t().showStatus( strStatus);
            }*/
            public void actionPerformed (ActionEvent ae)
            {
            Object obj=ae.getSourc e();
            if(obj==enter)
            {
            String code;
            code=t.getText( );
            if(obj==enter)
            if(code.length( )==0)
            {
            JOptionPane.sho wMessageDialog( frame ," Please . . .\n"+
            "Enter the Access Code");
            }
            else if(code.equals( "Jyotshna") )
            {
            t.setText("");
            cl.show(card,"P anel2");
            }
            else if(code.length( ) > 8 )
            {
            JOptionPane.sho wMessageDialog( frame ,"Access Code cannot exceed more than 8 digits . . . ");
            }
            else
            {
            JOptionPane.sho wMessageDialog( frame ," Sorry . . . \n" +
            " Invalid Access Code");
            return;
            }
            }
            Object source=ae.getSo urce();
            if(source==add)
            {
            String name,cell,landl ine,textarea,em ail,birthday;
            name=t1.getText ();
            cell=t2.getText ();
            landline=t3.get Text();
            textarea=ta.get Text();
            email=t6.getTex t();
            birthday=t7.get Text();
            if(name.length( )==0)
            {
            pobj.showMessag eDialog(frame,( "Friends Name cannot be left blank") , "ErrorMessage", JOptionPane.ERR OR_MESSAGE);
            //JOptionPane.sho wMessageDialog( frame,"Friends Name cannot be left blank");
            return;
            }
            if(cell.length( )==0)
            {
            pobj.showMessag eDialog(frame,( "Cell number is must . It cannot be left blank") , "ErrorMessage", JOptionPane.ERR OR_MESSAGE);
            //JOptionPane.sho wMessageDialog( frame,"Gender is must . It cannot be left blank");
            return;
            }
            /*if(landline.le ngth()==0)
            {
            pobj.showMessag eDialog(frame,( "LandLine number is must . It cannot be left blank") , "ErrorMessage", JOptionPane.ERR OR_MESSAGE);
            //JOptionPane.sho wMessageDialog( frame,"Gender is must . It cannot be left blank");
            return;
            }
            if(textarea.len gth()==0)
            {
            pobj.showMessag eDialog(frame,( "Address is must . It cannot be left blank") , "ErrorMessage", JOptionPane.ERR OR_MESSAGE);
            //JOptionPane.sho wMessageDialog( frame,"Gender is must . It cannot be left blank");
            return;
            }
            if(email.length ()==0)
            {
            pobj.showMessag eDialog(frame,( "E - mail address is must . It cannot be left blank") , "ErrorMessage", JOptionPane.ERR OR_MESSAGE);
            //JOptionPane.sho wMessageDialog( frame,"Gender is must . It cannot be left blank");
            return;
            }*/
            try
            {
            //Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
            con=DriverManag er.getConnectio n("jdbc:odbc:Fr iends","sa","jy otshna");
            stat=con.prepar eStatement("Ins ert into Friends(Name,Ce ll,LandLine,Add ress,City,E_mai l,Birthday) values(?, ?, ?, ?, ?, ?, ?)");
            stat.setString( 1,t1.getText()) ;
            stat.setString( 2,t2.getText()) ;
            stat.setString( 3,t3.getText()) ;
            stat.setString( 4,ta.getText()) ;
            stat.setString( 5,(String)citie s.getSelectedIt em());
            stat.setString( 6,t6.getText()) ;
            stat.setString( 7,t7.getText()) ;
            stat.executeUpd ate();
            pobj.showMessag eDialog(frame,( " Congratulations ! ! ! \n" +
            "Your Details have been added to the Database") , "Successful l Message",JOptio nPane.INFORMATI ON_MESSAGE);
            //JOptionPane.sho wMessageDialog( frame,new String ("Congratulatio ns ! ! ! Your Details have been Accepted"));
            t1.setText("");
            t2.setText("");
            t3.setText("");
            ta.setText("");
            //cities.setText( "-----Select----");
            t6.setText("");
            t7.setText("");
            }
            catch(Exception exception)
            {
            pobj.showMessag eDialog(frame,( " Sorry . . . \n" +
            "Record has not been Added to the Database" ) , "Error Message",JOptio nPane.ERROR_MES SAGE);
            //JOptionPane.sho wMessageDialog( frame,new String("Error occured while entering Data into the Database" +exception));
            }
            }
            if(source == del)
            {
            String name;
            name=t1.getText ();
            if(name.length( )==0)
            {
            pobj.showMessag eDialog(frame,( "Friends Name cannot be left blank") , "Error Message",JOptio nPane.ERROR_MES SAGE);
            //JOptionPane.sho wMessageDialog( frame,"Friends Name cannot be left blank");
            return;
            }
            try
            {
            //Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
            con=DriverManag er.getConnectio n("jdbc:odbc:Fr iends","sa","jy otshna");
            stat=con.prepar eStatement("Del ete Friends where Name = ? ");
            stat.setString( 1,t1.getText()) ;
            stat.executeUpd ate();
            pobj.showMessag eDialog(frame,( "The Details that you have entered have been Deleted in the Database") , "Informatio n Message",JOptio nPane.INFORMATI ON_MESSAGE);
            //JOptionPane.sho wMessageDialog( frame,new String("The Details that you have entered have been Deleted in the Database"));
            t1.setText("");
            t2.setText("");
            t3.setText("");
            ta.setText("");
            t6.setText("");
            t7.setText("");
            }
            catch(Exception e)
            {
            JOptionPane.sho wMessageDialog( frame,new String("Error occured while deleting the Data from the Database" +e));
            }
            }
            if(source == update)
            {
            String name;
            name=t1.getText ();
            if(name.length( )==0)
            {
            pobj.showMessag eDialog(frame,( "Friends Name cannot be left blank") , "Error Message",JOptio nPane.ERROR_MES SAGE);
            //JOptionPane.sho wMessageDialog( frame,"Friends Name cannot be left blank");
            return;
            }
            try
            {
            Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
            con=DriverManag er.getConnectio n("jdbc:odbc:Fr iends","sa","jy otshna");
            //stat=con.prepar eStatement("Upd ate Friends set(Name=?,Cell =?,LandLine=?,A ddress=?,City=? ,E_mail=?,Birth day=? where Name=?)");
            stat=con.prepar eStatement( "Update Friends set Cell=? LandLine=? Address=? City=? E_mail=? Birthday=? where Name=?");
            stat.setString( 1,t1.getText()) ;
            stat.setString( 2,t2.getText()) ;
            stat.setString( 3,t3.getText()) ;
            stat.setString( 4,ta.getText()) ;
            stat.setString( 5,(String)citie s.getSelectedIt em());
            stat.setString( 6,t6.getText()) ;
            stat.setString( 7,t7.getText()) ;
            stat.executeUpd ate();
            pobj.showMessag eDialog(frame,( "UPDATED ") , "Informatio n Message",JOptio nPane.INFORMATI ON_MESSAGE);
            //JOptionPane.sho wMessageDialog( frame,new String("The details that you have entered have been deleted in the database successfully")) ;
            }
            catch(Exception e)
            {
            JOptionPane.sho wMessageDialog( frame,new String(""+e));
            //JOptionPane.sho wMessageDialog( frame,new String(" Sorry !" +e));
            }
            }
            if(source==exit )
            {
            System.exit(0);
            }
            if(source==quer y)
            {
            try
            {
            String name,gender;
            name=t1.getText ();
            if(name.length( )==0)
            {
            JOptionPane.sho wMessageDialog( frame,"Friends Name cannot be left blank");
            return;
            }
            stat1.setString (1,t1.getText() );
            result=stat1.ex ecuteQuery();
            result.next();
            }
            catch(Exception e)
            {
            JOptionPane.sho wMessageDialog( frame,"Could not execute the Query"+e );
            }
            showRecord(resu lt);
            }
            }
            public void showRecord(Resu ltSet result)
            {
            try
            {
            t1.setText(resu lt.getString(1) );
            t2.setText(resu lt.getString(2) );
            t3.setText(resu lt.getString(3) );
            ta.setText(resu lt.getString(4) );
            //cities.setText( result.getStrin g(5));
            t6.setText(resu lt.getString(6) );
            t7.setText(resu lt.getString(7) );
            }
            catch(Exception e)
            {
            JOptionPane.sho wMessageDialog( frame," Sorry . . . \n" +
            "The ' NAME ' you entered does not exists in the Database");

            //JOptionPane.sho wMessageDialog( frame,"The NAME you entered does not exists in the Database "+ e);
            }

            }
            }
            Last edited by andhraprince; Aug 2 '10, 07:07 AM. Reason: Forgot to past the program file

            Comment

            Working...