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

  • Home
  • SEARCH
  • 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 8843557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:15:15+00:00 2026-06-14T11:15:15+00:00

What I Want to Do ? I have a Class Customers that has a

  • 0

What I Want to Do ?

I have a Class Customers that has a variable dob // Date of Birth

I am trying to take an input from the user using a java Swing Text Field.

Convert it into a java date and then convert into java.sql.Date, so that i can store it in my MySQL database.

This is the setter method for Customer class

public  void setDOB(java.sql.Date dob)
{
    DateOfBirth = dob;
}   

Here is the code for my Swing Class(Application Window Loader)

//Date
            if(textField_5.getText().isEmpty())
                lblerr.setVisible(true);
            else
            {
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYYY");
                    Date dob = null;
                    dob = sdf.parse(textField_5.getText());
                    java.sql.Date sqlDate = new java.sql.Date(dob.getTime());
                    c1.setDOB(sqlDate);

                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                allinfoisentered = true;
            }   

textField_5 – is the Field Where User Inputs the Date.

I Tested My App With the following different inputs :

  1. 12-12-1993
  2. 10-05-1970

The Problem Is : The value that gets stored in MySQL Table is 1992-12-27, i have a strong feeling that this is some default date.

I want to know, How do i parse the string into Date and then send it to MySQL table.

  • 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-14T11:15:16+00:00Added an answer on June 14, 2026 at 11:15 am

    (As discussed in comments…)

    You have two problems:

    • Your parsing format is incorrect. It should use “yyyy” instead of “YYYY”
    • More importantly (IMO) your error handling is incorrect. You’re using this catch block:

      catch (ParseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      

      … which means that even if parsing fails, you’ll insert all the data except the date, which wouldn’t have been set. You should have been able to get the information from the log files anyway, but presumably either you’re not logging System.err, or you didn’t look at the logs.

    Error handling is very important. If an exception occurs when parsing the data, I would expect you not to want to insert the record at all – instead, the error should be propagated up the stack, forcing you to take note of it, and not losing the information. So you probably wanted something like this instead:

    catch (ParseException e) {
        throw new DataValidationException(
            "Error parsing date: " + textField_5.getText(), e);
    }
    

    (Where DataValidationException is just a made-up exception – you should consider what you want to use consistently in your app.)

    Two things are vitally important when an error occurs:

    • You should handle it properly at the time. Often this means aborting the current operation, although in some cases you could retry, or continue without some unimportant information.
    • You should capture enough information to understand the error later.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a class property that allow for an expression to take
This has defeated me. I want to have a static class variable which is
I have class and I want to initalize column that stores pictuer with type
I want to have a template class that looks something like what I have
I have a class that inherits QMainWindow and I just want it to have
I have a REST service and I want to have a helper class that
I have a class that I want to contain multiple objects of something I
We have a legacy application that has a class like this : public class
I have an abstract base class Contact that has two subclasses: Person and Company
I have set the PHP variable $accountnumber to be that of the user who

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.