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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:56:01+00:00 2026-05-31T02:56:01+00:00

i have written a code, where if a button is pressed, values from textfields

  • 0

i have written a code, where if a button is pressed, values from textfields shall be taken to create a record in a database. the code compiles but when i run it, i get this error message:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'From, To, TotalDays, VacationType, Notes, Signature, Date) VALUES('','','','',''' at line 1

Any suggestions?

    final JButton btnSubmit = new JButton("Submit");
    btnSubmit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {                 
        try {

            String vacationid = text_vacationID.getText();
            String staffid = text_staffID.getText();
            String from = text_from.getText();
            String to = text_to.getText();
            String totaldays = text_totalDays.getText();
            String vacationtype = text_vacationType.getText();
            String notes = textArea.getText();
            String signature = text_signature.getText();
            String date = text_date.getText();


            String sql = "INSERT into vacation (VacationID, StaffID, From, To, TotalDays, VacationType, Notes, Signature, Date) VALUES" + "(?,?,?,?,?,?,?,?,?)";    

            PreparedStatement prest = con.prepareStatement(sql);
            prest.setString(1, vacationid);
            prest.setString(2, staffid);
            prest.setString(3, from);
            prest.setString(4, to);
            prest.setString(5, totaldays);
            prest.setString(6, vacationtype);
            prest.setString(7, notes);
            prest.setString(8, signature);
            prest.setString(9, date);

            prest.executeUpdate();
            JOptionPane.showMessageDialog(frmBookVacation, "Vacation has been booked for Employee with ID: " + vacationid);


        } 

        catch (SQLException e) {
        //System.out.println("Record couldn't be added!");
        e.printStackTrace();
        JOptionPane.showMessageDialog(frmBookVacation, "Vacation couldn't be booked. Please try again.");
        }
        }

        });
    btnSubmit.setBounds(201, 350, 89, 23);
    panel_1.add(btnSubmit);
  • 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-05-31T02:56:02+00:00Added an answer on May 31, 2026 at 2:56 am

    From is a reserved word in MySQL. Also you can get rid of all those fields from your table in the code as the following:

    String sql = "INSERT into vacation VALUES" + "(?,?,?,?,?,?,?,?,?)";    
    

    That should work.

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

Sidebar

Related Questions

I have written is code below, but button isn't shown because i've set FILL_PARENT
I have written following code to set the status of the image button to
I am new to VBA. I have written this code inside a button click
I have written following code which generates a browse and upload button.i want to
I have written code that opens 16 figures at once. Currently, they all open
I have written code in Java to access web cam,and to save image... I
I have written code to perform a function that could take a while to
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
I have written some code for playing a .wav through my application. Now I
I have written this code to join ArrayList elements: Can it be optimized more?

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.