Solved

A Question About Insert

Posted on 1998-09-03
6
157 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now