Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:14:05+00:00 2026-06-18T16:14:05+00:00

I am trying to validate some input from a Swing form by checking for

  • 0

I am trying to validate some input from a Swing form by checking for null values. However the checkFirstName method is always returning true. So for example if i leave the firstname blank on the form it will return true even though the field is null.

Here is my two methods, the first one is fired when the user clicks the save button.

public void saveNewCustomer() throws SQLException, ClassNotFoundException {

        boolean dbOK = false;//boolean to check if data input is not null

        System.out.println(dbOK);
        String firstName = txtNCustomerFirstName.getText();
        String lastName = txtNCustomerLastName.getText();

        if (checkFirstName(firstName)) {
            dbOK = true;
        } else {
            lblNCustFirstNameError.setText("First Name Must be Entered");
            dbOK = false;
        }
        System.out.println(dbOK);

        if (dbOK) {
            dbConnector.insertSignup(firstName, lastName);
            System.out.println("Success");
        } else {
            System.out.println("Error");
        }
    }

    public boolean checkFirstName(String firstName) {
        boolean allOK = false;
        System.out.println(allOK);

        if (firstName != null) {
            allOK = true;
        } else {
            allOK = false;
        }
        return allOK;
    }

Have i done something wrong cause this to me should be return false cause the firstname field is null.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:14:07+00:00Added an answer on June 18, 2026 at 4:14 pm

    So for example if i leave the firstname blank on the form

    You are just checking for null, you need to do empty ("") String check also.

    It should be something like:

    if (firstName != null && !"".equals(firstName.trim()) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to validate some form data before adding it to a database however
I am trying to use jquery validation to validate some input values on the
I'm trying to validate some of the field in my form. and I want
I'm trying to validate a contact form and I want to create some sort
I am validating some input from a Restlet URL in a utility method (that
Im new to php and trying to validate some fields in the user form
Hi I am trying to validate some user input and I'm not sure what
I am trying to validate form input data using PHP's preg_match function. I am
i'm trying to send some radio buttons from a form with ajax, the problem
Right what I was trying to do is validate some input so that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.