?
Solved

A Insert Problem

Posted on 1998-08-30
2
Medium Priority
?
220 Views
Last Modified: 2010-03-30
If the user doesn't input information in all of the TextFields, the following code will cause a run-time error. Because  some value of the getText() are null.  Can anybody tell me how to deal with this situation? Thanks!

void doInsert() throws SQLException
{        
  query = "INSERT INTO GenInf VALUES (" + txtID.getText() + ", '" +
  txtDate.getText() + "', '" +
  txtName.getText() + "', '" +
  txtHost.getText() + "', '" +
  txtLocation1.getText() + "', '" +
  txtLocation2.getText() + "', " +
  txtACFee.getText() + ", " +
  txtACSrFee.getText() + ", " +
  txtACStFee.getText() + ", " +
  txtOCFee.getText() + ", " +
  txtOCSrFee.getText() + ", " +
  txtOCStFee.getText() + ", " +
  txtTShirtP.getText() + ", " +
  txtDinnerP.getText() + ", " +
  xtHousingP.getText() + ", " +
  txtDiscount.getText() + ", '" +
  txtSTFrom.getText() + "', '" +
  txtSTTo.getText() + "')";
   s=c.createStatement();      
   s.executeUpdate(query);
             
}
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
2 Comments
 

Author Comment

by:Jun080298
ID: 1222950
Edited text of question
0
 

Accepted Solution

by:
milen_n earned 80 total points
ID: 1222951
Subclass TextField and override getText() so it will return an empty String insted of null:

public String getText()
{
  String s = super.getText();
  if(s == null) return new String();
  return s;
}

Then use the new class instead of TextField.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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