473,698 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error in Do While Loop

6 New Member
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.prin tln("Beginning Connection");
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
String accessFileName = "jdbc:odbc:Proj ect";
String connURL = "jdbc:odbc:;DRI VER=Microsoft Access Driver (*.mdb);DBQ="+a ccessFileName+" .mdb;PWD=";
Connection con = DriverManager.g etConnection( accessFileName) ;
Statement stmt = con.createState ment();
System.out.prin tln("Connection done successfully");
stmt.execute("C reate table Member(Name String,EMAIL String,Telephon e String)");
System.out.prin tln("Table Created");
do{


System.out.prin tln("Please, Enter the Member Name : ");
InputStreamRead er istream = new InputStreamRead er (System.in);
BufferedReader br = new BufferedReader (istream);

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

System.out.prin tln("Please, Enter the E-Mail Address : ");
InputStreamRead er isr = new InputStreamRead er (System.in);
BufferedReader bfr = new BufferedReader (isr);

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

System.out.prin tln("Please, Enter the Telephone number : ");
InputStreamRead er ism = new InputStreamRead er (System.in);
BufferedReader bb = new BufferedReader (ism);

tel=String.valu eOf(bb.readLine ());
stmt.execute("i nsert into Member (Name,EMAIL,Tel ephone) values ('"+mname+"','" +mail+"','"+tel +"')");
System.out.prin tln("Insertion has been completed");
stmt.execute(" select * from Member");
ResultSet rs=stmt.getResu ltSet();

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

System.out.prin tln("Do you want to insert more records? ");
InputStreamRead er is = new InputStreamRead er (System.in);
BufferedReader bbb = new BufferedReader (is);
ans=String.valu eOf(bbb.readLin e());

}
catch (IOException err)
{

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

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


}

catch (IOException err)
{

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

}

catch (IOException err)
{

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

}
catch (IOException err)
{

System.out.prin tln("Error in reading the numbers");
}
}while(ans=="ye s");
}


catch (Exception err) {err.printStack Trace();}

}
}[/PHP]
Aug 5 '07 #1
1 1798
JosAH
11,448 Recognized Expert MVP
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
14618
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 a total mistery. I have a function inside an ASP page as a result of which I get the following error message: Microsoft VBScript compilation error '800a03ea'
1
3719
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, sequential date ranges. I.E. from 9/1/2000 - 10/1/2000 then 10/1/2000 - 11/1/2000 etc etc etc. It calls SPs using the 2 dates and an integer used for companyid reference.
14
10131
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 I should give back to the community by posting our findings. Thanks you all for all your help till now by posting problems and their solutions. ~Abhijit
3
15954
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 loop. Is there some way to send a break from VBA code to break out of the loop? Here's what the error handler code looks like: Private Function MyFunction On Error GoTo HandleErr
4
13003
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 value". Any idea as to what I'm doing wrong? I'm sure it's something simple. Thanks in advance! public class ForLoop
1
1784
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, ----------------------------------------------------------------------------- Option Compare Database Option Explicit Private Sub Command26_Click()
35
3780
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 gets about 3 or so. It also gets very awkward in nested loops, where you want to check for normal loop processing in the loop condition, not errors. Yes, you could put some generic exit flag in the loop condition, but when you're simply done if...
1
4926
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 following error. SQL> execute domsample('c:\','song.xml','error.txt') BEGIN domsample('c:\','song.xml','error.txt * ERROR at line 1: ORA-31001: Invalid resource handle or path
0
4042
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 following error. SQL> execute domsample('c:\','song.xml','error.txt') BEGIN domsample('c:\','song.xml','error.txt * ERROR at line 1: ORA-31001: Invalid resource handle or path
11
5584
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 Tools Test PC :- .Net Framework 2
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.