Solved

A Insert Problem

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

717 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