This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 14074
    
  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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If statement problem!!
 
Similar Threads
need help. I have problems running the client
NoClassDefFoundError
Web-based GUI using JDBC
3 problems with my applet...
Generating swing components on fly slow