Solved

A Question About Insert

Posted on 1998-09-03
6
161 Views
Last Modified: 2010-03-30
This question is 40 points, not 20 points.
I have a big registration form. I wrote myTextField extending TextField
in order to make sure that there are no problem in doing INSERT and UPDATE
when the user just inputs some of these text fields. The following piece of
code getText() in myTextField is OK for value of data type "Text" in database, but for
the value of data type "Number" in database will cause syntax error. I need a correct
function getText().
For example:
query = "UPDATE regist " +
        "SET lastName = '" + txtlastName + "'," +
        "TotalBal = " + txtTotalBal.getText() +
        " WHERE bibNo = 100 ";    
If the text fields are blank, the query is:
UPDATE regist SET lastName = '',TotalBal =  WHERE bibNo = 100
The value of TotalBal should be 0, not empty.                                  


public String getText()
{
     String s = super.getText();
     if(s == null) return new String();
     return s;
}
0
Comment
Question by:Jun080298
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:Jun080298
ID: 1223493
Edited text of question
0
 
LVL 8

Expert Comment

by:diakov
ID: 1223494
Change
txtTotalBal.getText()
to
(txtTotalBal.getText().equals(""))?"0":txtTotalBal.getText()
0
 

Author Comment

by:Jun080298
ID: 1223495
Hi, diakov.
I got an error message after changing the code
from
      txtTotalBal.getText()
to
    (txtTotalBal.getText().equals(""))?"0":txtTotalBal.getText()

"Incompatible type for ?: Can't convert java.lang.String to boolean"
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Expert Comment

by:pureDan
ID: 1223496
U 've got to test if the txtTotalBal is empty or not  .
It isn't necessary to overwrite getText() method.
Just a simple test like the next one :
   if(txtTotalBal.getText().equals(""))  txtTotalBal.setText("0");
                  else txtTotalBal.getText();

0
 
LVL 8

Accepted Solution

by:
diakov earned 20 total points
ID: 1223497
Sorry for the inconvenience. You need also some additional brackets:
from
txtTotalBal.getText()
to
( (txtTotalBal.getText().equals(""))?"0":txtTotalBal.getText() )
0
 
LVL 7

Expert Comment

by:linda101698
ID: 1223498
pureDan,
Jun requested I award you points for your help.  See the question posted in this topic area for you to answer to receive points.

Linda Gardner
Customer Service @ Experts Exchange.


0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 83
Glassfish admin console not working 1 88
Is Applet the way to go for my drag and drop system? 8 51
Firefox and firebub 5 26
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question