473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error in Do While Loop

6
hello

i have a problem in the do while loop
where the program will ask the user to enter yes and do an iteration, nut in my example it did not do??

here is the code

[PHP]import java.sql.*;
import java.io.*;
public class Project3A {

public static void main(String[] args) {
String mname="";
String mail="";
String tel="";
String ans="";
try {

System.out.println("Beginning Connection");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String accessFileName = "jdbc:odbc:Project";
String connURL = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ="+accessFileName+".mdb;PWD=";
Connection con = DriverManager.getConnection( accessFileName);
Statement stmt = con.createStatement();
System.out.println("Connection done successfully");
stmt.execute("Create table Member(Name String,EMAIL String,Telephone String)");
System.out.println("Table Created");
do{


System.out.println("Please, Enter the Member Name : ");
InputStreamReader istream = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (istream);

try{
mname= (br.readLine());

System.out.println("Please, Enter the E-Mail Address : ");
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader bfr = new BufferedReader (isr);

try
{
mail= (bfr.readLine());
try{

System.out.println("Please, Enter the Telephone number : ");
InputStreamReader ism = new InputStreamReader (System.in);
BufferedReader bb = new BufferedReader (ism);

tel=String.valueOf(bb.readLine());
stmt.execute("insert into Member (Name,EMAIL,Telephone) values ('"+mname+"','"+mail+"','"+tel+"')");
System.out.println("Insertion has been completed");
stmt.execute(" select * from Member");
ResultSet rs=stmt.getResultSet();

if (rs != null)
while (rs.next()){
System.out.println("Name: "+rs.getString("Name")+ " E-MAIL: " + rs.getString("EMAIL")+" Telephone: "+rs.getString("Telephone"));
}
try{

System.out.println("Do you want to insert more records? ");
InputStreamReader is = new InputStreamReader (System.in);
BufferedReader bbb = new BufferedReader (is);
ans=String.valueOf(bbb.readLine());

}
catch (IOException err)
{

System.out.println("Error in reading the numbers");
}

stmt.close();
con.close();


}

catch (IOException err)
{

System.out.println("Error in reading the numbers");
}

}

catch (IOException err)
{

System.out.println("Error in reading the numbers");
}

}
catch (IOException err)
{

System.out.println("Error in reading the numbers");
}
}while(ans=="yes");
}


catch (Exception err) {err.printStackTrace();}

}
}[/PHP]
Aug 5 '07 #1
1 1785
JosAH
11,448 Expert 8TB
Line 94 in your code:

Expand|Select|Wrap|Line Numbers
  1.           }while(ans=="yes");  
  2.  
Don't compare Strings like that; you should use the 'equals()' method. Check out
the API docs for the String class.

kind regards,

Jos
Aug 5 '07 #2

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

Similar topics

5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
1
by: Beau | last post by:
Hi all, thanks in advance. Ok, heres the story. What is happening...... -------------------------------- I've got an ASP page that loops. It loops in order to get data in different,...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
3
by: deko | last post by:
I have a logging routine that's supposed to silently log errors caught by error handler code on certain functions. The problem is sometimes stuff happens and the error handler can get caught in a...
4
by: OutdoorGuy | last post by:
Greetings, I am attempting to compile the code below, but I am receiving an error message when I do so. The error message is: "CSO161: 'Forloop.CalcAvg(int)': Not all code paths return a...
1
by: Eric | last post by:
When I run my script it gives error on the following line: strEmail = Right(strEmail, (Len(strEmail) - 1)) I enclose my code and the sample text file too Thanks,...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
1
by: janakivenk | last post by:
Hello, I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The procedure is compiled and when I try to run it, i get the...
0
by: janakivenk | last post by:
Hello, I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The procedure is compiled and when I try to run it, i get the...
11
by: xenoix | last post by:
hey there, im reasonably new to C# and im currently writing a backup application which im using as a learning resource. My PC :- Visual Studio 2005 .NET Framework 2 Component Factory Krypton...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.