Solved

A Insert Problem

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

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

Title # Comments Views Activity
DO we need Java installed on a Windows PC and WHY ? 13 97
Where to store the queries for modification of table 4 55
Error trying to install RTMT Win7 5 41
javap bin 2 28
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…
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

910 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

21 Experts available now in Live!

Get 1:1 Help Now