Link to home
Start Free TrialLog in
Avatar of Jun080298
Jun080298

asked on

A Question About Insert

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;
}
Avatar of Jun080298
Jun080298

ASKER

Edited text of question
Change
txtTotalBal.getText()
to
(txtTotalBal.getText().equals(""))?"0":txtTotalBal.getText()
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"
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();

ASKER CERTIFIED SOLUTION
Avatar of diakov
diakov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.