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);