Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

A Insert Problem

Posted on 1998-08-30
2
Medium Priority
?
225 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

604 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