aspose 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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 14114
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
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!
 
Don't get me started about those stupid light bulbs.
 
subject: If statement problem!!