Solved

A Question About Insert

Posted on 1998-09-03
6
158 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

863 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

24 Experts available now in Live!

Get 1:1 Help Now