I'm trying to insert data into my SQL tables. I have a Jframe:
The purpose of the form is to input whatever is written on these text fields into the database. My problem is that when I press Send Request, nothing happens.. Am I missing something?
This is my code for the Send Request button:
private void SendRequestActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/database","my-user","my-pass");
Statement stmt = con.createStatement();
//execute commands that collects
//the text/items from the fields and converts them to strings
String MedRole = ofMedRoleComboBox.getSelectedItem().toString();
String PtID = ofPatientIDField.getText();
String Date = ofDateField.getText();
String Time = ofTimeField.getText();
String Purpose = ofPurposeComboBox.getSelectedItem().toString();
// sql query
String insertOrdersDB = "INSERT INTO Orders ('PatientID','MedicalRole','Date','Time','Purpose') VALUES ("+MedRole+","+PtID+","+Date+","+Time+","+Purpose+")";
// executing sql query
stmt.executeUpdate(insertOrdersDB);
}
catch (Throwable e) {
e.printStackTrace();
}
}
In e.printStackTrace(); is:
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 ''PatientID','MedicalRole','Date','Time','Purpose') VALUES (Nurse,7,2016-04-13,12' at line 1
I was thinking it was the date syntax, which is different from the SQL. So I changed it to match the SQL table format. But still got the same error.
Now I think it's regarding the Time ?