Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

A Question About Insert

Posted on 1998-09-03
6
Medium Priority
?
169 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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 80 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

927 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