File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes If statement problem!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "If statement problem!!" Watch "If statement problem!!" New topic
Author

If statement problem!!

Peter Matthews
Greenhorn

Joined: Nov 07, 2005
Posts: 21
Hi All,

I'm experiencing a strange problem with my if statement. Basically, I'm wanting an error message to come up when a user does not enter a name. However at the moment, the if statement always produces the same result - even if there is no data entered into the txt field. So at the moment, all the respones from the validateText() method are "Good", even when there is no text in the text field. Any help would be very appreciated. Thanks. Pete


James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
use .equals() to compare your Strings instead of ==
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

String order = "INSERT INTO orders (name,type,capacity,voltage,quantity) " +"values ('"+ cust+"','"+ type +"','"+ capacity+"','"+voltage+ "','"+ quantity+"')";


Appending SQL statements together like that is a bad idea. You should use PreparedStatement. Look it up in the API documentation.


[ November 16, 2005: Message edited by: Jesper de Jong ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Pratik Lohia
Ranch Hand

Joined: May 05, 2005
Posts: 88
hey... cust is a string ... yu cannot use == on that. That will compare references and not the data. Use cust.equals("") instead
Peter Matthews
Greenhorn

Joined: Nov 07, 2005
Posts: 21
thanks guys - appreciate the help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If statement problem!!