SQLテーブルにデータを挿入しようとしています。SQL DBにデータを挿入するときにアクションボタンが機能しない - Java
フォームの目的は、データベースにこれらのテキストフィールドの上に書かれているものは何でも入力することです:私はJFrameのを持っています。 私の問題は、を送信すると、を送信すると、何も起こりません。何か不足していますか?
これはSEND要求ボタンの私のコードです:e.printStackTrace(で
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();
}
}
)。は:
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
私はそれがSQLとは異なる日付の構文だと思っていました。だから私はそれをSQLテーブル形式と一致するように変更しました。しかし、同じエラーがまだあります。
今は時間に関するものだと思いますか?
?また、catchする可能性のある例外のスタックトレースを出力します。 – Berger
e.printStrackTrace()をキャッチブロックに追加して、エラーが発生している場合はそれを取り除き、ここに投稿してください。 –
スタックトレースをcatchブロックに追加する必要があります。おそらくSQL例外がスローされますが、あなたはそれを見ることはできません。 –