Solved

A Insert Problem

Posted on 1998-08-30
2
175 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
2 Comments
 

Author Comment

by:Jun080298
ID: 1222950
Edited text of question
0
 

Accepted Solution

by:
milen_n earned 20 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

762 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

28 Experts available now in Live!

Get 1:1 Help Now