473,473 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I/O Exception Java Error

1 New Member
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.?
Apr 7 '06 #1
5 11779
jagannathan
11 New Member
please send the code where u get this error
Jul 10 '06 #2
mahammadseeraz
6 New Member
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.
Jul 30 '07 #3
r035198x
13,262 MVP
U might have these problems
1. didn't throw IOException
2. Import IO package.
No. The OP doesn't have any of those problems.
Jul 30 '07 #4
JosAH
11,448 Recognized Expert MVP
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
Jul 30 '07 #5
andhraprince
1 New Member
[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 PreparedStatement stat,stat1,stat2;
static Connection con,conn,connn;
static ResultSet result;
JOptionPane pobj;

JLabel l,l1,l2,l3,l4,l5,l6,l7;
TextField t,t1,t2,t3,t6,t7;
TextArea ta;
Choice cities;
JButton enter,add,del,query,update,exit,truncate;
FlowLayout fl;
CardLayout cl;
GridBagLayout gbl,gbl2,gbl3;
GridBagConstraints gbc,gbc2,gbc3;
Thread th;
//Date date;
GregorianCalendar calendar;
String strDate,strTime,strStatus;

public Friends()
{
frame=new JFrame(" Friends Contact Numbers and their Birthday Dates ");
frame.setSize(500,500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
main=new JPanel();
card=new JPanel();
frame.getContentPane().add(main);

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

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

gbc.anchor=GridBagConstraints.CENTER;
gbc.gridx=1;
gbc.gridy=2;
gbl.setConstraints(card,gbc);
main.add(card);
main.setBackground(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("LandLine");
l4=new JLabel("Address");
l5=new JLabel("City");

cities=new Choice();
//cities.setBackground(Color.yellow);
cities.setFont(font);
cities.addItem("----------Select----------");
cities.addItem("Hyderabad");
cities.addItem("Bangalore");
cities.addItem("Guntakal");
cities.addItem("Chattisgard");

t1=new TextField(17);
t1.setFont(font);
t1.setForeground(Color.blue);
//t1.setBackground(Color.yellow);
t2=new TextField(17);
t2.setFont(font);
//t2.setBackground(Color.yellow);
t3=new TextField(17);
t3.setFont(font);
t3.setForeground(Color.blue);
//t3.setBackground(Color.yellow);
ta=new TextArea(3,17);
ta.setFont(font);
ta.setForeground(Color.blue);
//ta.setBackground(Color.yellow);
l6=new JLabel("E - mail ");
t6=new TextField(17);
t6.setFont(font);
//t6.setBackground(Color.yellow);
l7=new JLabel("Birthday");
t7=new TextField(17);
t7.setFont(font);
//t7.setBackground(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("Truncate");

p1=new JPanel();
p1.setLayout(gbl2);
p1.setBackground(Color.cyan);

gbc2.anchor=GridBagConstraints.CENTER;
gbc2.gridx=1;
gbc2.gridy=1;
gbl2.setConstraints(l,gbc2);
p1.add(l);
gbc2.anchor=GridBagConstraints.CENTER;
gbc2.gridx=2;
gbc2.gridy=1;
gbl2.setConstraints(t,gbc2);
p1.add(t);
gbc2.anchor=GridBagConstraints.CENTER;
gbc2.gridx=2;
gbc2.gridy=2;
gbl2.setConstraints(enter,gbc2);
p1.add(enter);
enter.addActionListener(this);
//enter.addMouseListener(this);
enter.setToolTipText("Enter the required code in the Text Box and Click this button to go to the next page");

p2=new JPanel();
p2.setLayout(gbl3);
p2.setBackground(Color.cyan);

gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=5;
gbc3.gridy=1;
gbl3.setConstraints(truncate,gbc3);
p2.add(truncate);
truncate.setFont(font);
truncate.setToolTipText("Click this button to Truncate the data in the Database");
truncate.addActionListener(this);


gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=1;
gbl3.setConstraints(l1,gbc3);
p2.add(l1);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=1;
gbl3.setConstraints(t1,gbc3);
p2.add(t1);

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

gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=1;
gbc3.gridy=8;
gbl3.setConstraints(add,gbc3);
p2.add(add);
add.setFont(font);
add.setToolTipText("Click this button to Add the details you have entered to the Database");
add.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=2;
gbc3.gridy=8;
gbl3.setConstraints(del,gbc3);
p2.add(del);
del.setFont(font);
del.setToolTipText("Click this button to Delete the details you have entered to the Database");
del.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=3;
gbc3.gridy=8;
gbl3.setConstraints(query,gbc3);
p2.add(query);
query.setFont(font);
query.setToolTipText("Click this button to View the details of your Friends that you have entered in the Database");
query.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=4;
gbc3.gridy=8;
gbl3.setConstraints(update,gbc3);
p2.add(update);
update.setFont(font);
update.setToolTipText("Click this button to Update the details of your Friends that you have entered in the Database");
update.addActionListener(this);
gbc3.anchor=GridBagConstraints.CENTER;
gbc3.gridx=5;
gbc3.gridy=8;
gbl3.setConstraints(exit,gbc3);
p2.add(exit);
exit.setFont(font);
exit.setToolTipText("Click this button to Exit ");
exit.addActionListener(this);

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

card.add(p1,"Panel1");
card.add(p2,"Panel2");
}
public void mousePressed(MouseEvent me)
{
cl.next(card);
}
public void mouseClicked(MouseEvent me)
{ }
public void mouseEntered(MouseEvent me)
{ }
public void mouseExited(MouseEvent me)
{ }
public void mouseReleased(MouseEvent me)
{ }

public static void main(String args[])
{
Friends friends=new Friends();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Friends ","sa","jyotshna");
stat1=con.prepareStatement("Select * from Friends where Name = ?");
}
catch(Exception e)
{
System.out.println("Could not execute the query " + e);
}
}
/*public void run()
{
while(th!=null)
{
disp();
try
{
th.sleep(1000);
}
catch(InterruptedException e)
{
getAppletContext().showStatus("Thread Interrupted");
}
}
}
public void disp()
{
date=new Date();
calendar=new GregorianCalendar();
calendar.setTime(date);
strTime=calendar.get(Calendar.HOUR)+ ":" +(calendar.get(Calendar.MINUTE)) +":"+(calendar.get(Calendar.SECOND));
strDate=(calendar.get(Calendar.MONTH)+1)+ ":" +calendar.get(Calendar.DATE)+":"+calendar.get(Cale ndar.YEAR);
strStatus=strTime+ " " +strDate;
getAppletContext().showStatus(strStatus);
}*/
public void actionPerformed(ActionEvent ae)
{
Object obj=ae.getSource();
if(obj==enter)
{
String code;
code=t.getText();
if(obj==enter)
if(code.length()==0)
{
JOptionPane.showMessageDialog(frame ," Please . . .\n"+
"Enter the Access Code");
}
else if(code.equals("Jyotshna"))
{
t.setText("");
cl.show(card,"Panel2");
}
else if(code.length() > 8 )
{
JOptionPane.showMessageDialog(frame ,"Access Code cannot exceed more than 8 digits . . . ");
}
else
{
JOptionPane.showMessageDialog(frame ," Sorry . . . \n" +
" Invalid Access Code");
return;
}
}
Object source=ae.getSource();
if(source==add)
{
String name,cell,landline,textarea,email,birthday;
name=t1.getText();
cell=t2.getText();
landline=t3.getText();
textarea=ta.getText();
email=t6.getText();
birthday=t7.getText();
if(name.length()==0)
{
pobj.showMessageDialog(frame,("Friends Name cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Friends Name cannot be left blank");
return;
}
if(cell.length()==0)
{
pobj.showMessageDialog(frame,("Cell number is must . It cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Gender is must . It cannot be left blank");
return;
}
/*if(landline.length()==0)
{
pobj.showMessageDialog(frame,("LandLine number is must . It cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Gender is must . It cannot be left blank");
return;
}
if(textarea.length()==0)
{
pobj.showMessageDialog(frame,("Address is must . It cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Gender is must . It cannot be left blank");
return;
}
if(email.length()==0)
{
pobj.showMessageDialog(frame,("E - mail address is must . It cannot be left blank") , "ErrorMessage",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Gender is must . It cannot be left blank");
return;
}*/
try
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Friends ","sa","jyotshna");
stat=con.prepareStatement("Insert into Friends(Name,Cell,LandLine,Address,City,E_mail,Bir thday) 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)cities.getSelectedItem()) ;
stat.setString(6,t6.getText());
stat.setString(7,t7.getText());
stat.executeUpdate();
pobj.showMessageDialog(frame,(" Congratulations ! ! ! \n" +
"Your Details have been added to the Database") , "Successfull Message",JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(frame,new String ("Congratulations ! ! ! Your Details have been Accepted"));
t1.setText("");
t2.setText("");
t3.setText("");
ta.setText("");
//cities.setText("-----Select----");
t6.setText("");
t7.setText("");
}
catch(Exception exception)
{
pobj.showMessageDialog(frame,(" Sorry . . . \n" +
"Record has not been Added to the Database" ) , "Error Message",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(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.showMessageDialog(frame,("Friends Name cannot be left blank") , "Error Message",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Friends Name cannot be left blank");
return;
}
try
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Friends ","sa","jyotshna");
stat=con.prepareStatement("Delete Friends where Name = ? ");
stat.setString(1,t1.getText());
stat.executeUpdate();
pobj.showMessageDialog(frame,("The Details that you have entered have been Deleted in the Database") , "Information Message",JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(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.showMessageDialog(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.showMessageDialog(frame,("Friends Name cannot be left blank") , "Error Message",JOptionPane.ERROR_MESSAGE);
//JOptionPane.showMessageDialog(frame,"Friends Name cannot be left blank");
return;
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Friends ","sa","jyotshna");
//stat=con.prepareStatement("Update Friends set(Name=?,Cell=?,LandLine=?,Address=?,City=?,E_ma il=?,Birthday=? where Name=?)");
stat=con.prepareStatement( "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)cities.getSelectedItem()) ;
stat.setString(6,t6.getText());
stat.setString(7,t7.getText());
stat.executeUpdate();
pobj.showMessageDialog(frame,("UPDATED ") , "Information Message",JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(frame,new String("The details that you have entered have been deleted in the database successfully"));
}
catch(Exception e)
{
JOptionPane.showMessageDialog(frame,new String(""+e));
//JOptionPane.showMessageDialog(frame,new String(" Sorry !" +e));
}
}
if(source==exit)
{
System.exit(0);
}
if(source==query)
{
try
{
String name,gender;
name=t1.getText();
if(name.length()==0)
{
JOptionPane.showMessageDialog(frame,"Friends Name cannot be left blank");
return;
}
stat1.setString(1,t1.getText());
result=stat1.executeQuery();
result.next();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(frame,"Could not execute the Query"+e );
}
showRecord(result);
}
}
public void showRecord(ResultSet result)
{
try
{
t1.setText(result.getString(1));
t2.setText(result.getString(2));
t3.setText(result.getString(3));
ta.setText(result.getString(4));
//cities.setText(result.getString(5));
t6.setText(result.getString(6));
t7.setText(result.getString(7));
}
catch(Exception e)
{
JOptionPane.showMessageDialog(frame," Sorry . . . \n" +
"The ' NAME ' you entered does not exists in the Database");

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

}
}
Aug 2 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: J. Muenchbourg | last post by:
I'm getting an Exception occured error on line 4 (For i =1...) <% Function ProperCase(strIn) strOut = "" boolUp = True For i = 1 To Len(strIn) c = Mid(strIn, i, 1) if c = " " or c = "'" or c...
1
by: manish | last post by:
Hi, I am a fresher in the programming field i.e although I have done programming at the basic level but at professional level I am very new and I am facing many problems. These probllems are...
5
by: Mark D Smith | last post by:
Hi anyone know what the java error is on this page? http://www.s-nta.org.uk/index.html Mark
0
by: sobhan | last post by:
Hi, Yhis is sobhan, i haveused Microsoft Access in my Application.it works fine but sometimes an error occurs oledb exception :Unspecified Error .what is the solution. plz help
4
by: cnixuser | last post by:
Hello, I am posting reguarding some modifications I made to a text editor program that I wrote in my java class at my school today. The file I was modifying is a very simple java text editor with...
8
by: AnnetteB | last post by:
I have a main java class named MainFrame in a project with another class named Buttons, which is called from MainFrame. The project is called pol2 but I keep getting this error message when I...
2
by: josephx | last post by:
Hello, I got some of these errors listed below after executing an HTTP Post MIDlet on CLDC/MIDP platform, "Nokia S40 DP 2.0 SDK 1.1" and "S40 5th Edition SDK Feature Pack 1" and even for S60's...
1
by: annazpereira | last post by:
Hi, I am new to java and cannot fiugre out what is wrong with my code. I keep getting the following error: Upgrade.java:133: unreported exception java.lang.Exception; must be caught or declared to...
7
by: blknmld69 | last post by:
My program checks a valid_accounts.txt to see if the input account number is valid. When i run the code with either a correct or incorrect code it outputs "the code is invalid" Can anyone help...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.