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 8836549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:31:19+00:00 2026-06-14T09:31:19+00:00

Let’s suppose we have a JFrame called FrmRegistration . Its function is inserting data

  • 0

Let’s suppose we have a JFrame called FrmRegistration. Its function is inserting data into a table called records.

MySQL’s command desc records would result the following:

+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| id        | varchar(7)   | NO   | PRI |         |       | 
| name      | varchar(100) | NO   |     | NULL    |       | 
| birthday  | date         | NO   |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+

Within FrmRegistration there’s a JFormattedTextField for birthday input we’ll call ftfBirthday. In Netbeans, we put names into components by right-clicking it and going to Properties -> Code tab -> Variable name. Or right-click -> Customize code -> Rename… button.

Right-click the field and go to Properties, then in FormatterFactory, click the “…” button. Create a customized field with: ####/##/##

The reason for a JFormattedTextField is that the user wouldn’t lose time by typing the slashes. They appear automatically.

What should be done in the source-code of a button in FrmRegistration called Insert?

  • 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-14T09:31:20+00:00Added an answer on June 14, 2026 at 9:31 am

    Before going to the source-code, right-click the date field and go to Properties. Copy the content of text. It should be (a = one space):

    aaaa/aa/aa

    It will be used in the “} else if (” / / “.equals(birthday)) {” line.

    (See the code for proper parameter)

    I added some things extra, like checking if fields are empty.

        try {
                    Class.forName("com.mysql.jdbc.Driver");
    
                    try (Connection con = DriverManager.getConnection(
    
                                    "jdbc:mysql://localhost/database_name_here",
                                    "username_here", "password_here")) {
    
                        String if = txtId.getText();
                        String name = txtName.getText();
                        String birthday = ftfBirthday.getText();
    
                        PreparedStatement stmt = con.prepareStatement(
    
                                "INSERT INTO records "
                                + "(id, name, birthday)"
                                + "VALUES(?,?,STR_TO_DATE(?,'%Y/%m/%d'))");
    
                        if (id.isEmpty()) {
                            JOptionPane.showMessageDialog(null,
                                    "The ID field must be completed!");
    
                        } else if (name.isEmpty()) {
                            JOptionPane.showMessageDialog(null,
                                    "The Name field must be completed!");
    
                        } else if ("    /  /  ".equals(birthday)) {
                            JOptionPane.showMessageDialog(null,
                                    "The Birthday field must be completed!");
    
                        } else {
    
                            stmt.setString(1, id);
                            stmt.setString(2, name);
                            stmt.setString(3, birthday);
    
                            stmt.executeUpdate();
    
                            JOptionPane.showMessageDialog(this, " Data was saved successfully! ");
    
                        }
    
                    }
    
                } catch (SQLException e) {
                    JOptionPane.showMessageDialog(this, "SQL command error "
                            + e.getMessage());
    
                } catch (ClassNotFoundException e) {
                    JOptionPane.showMessageDialog(this,
                            " Database driver not found ");
    
            }
    

    That’s it. Hope it helps someone! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have such MYSQL table for logins: id---name---location---login_date ---------------------------------- 1----mike----usa-----21.08.2012 2----tony----uk------22.08.2012 3----tony----uk------23.08.2012
Let's say I have a table with a Color column. Color can have various
Let's say I have two text files that I need to extract data out
Let's say I have the following data frame: > myvec name order_no 1 Amy
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Let's suppose I have an XML file like this: <?xml version=1.0 encoding=ISO-8859-1?> <MIDIFile> <Event>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have some data in a CouchDB database. The overall size is
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName

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.