java.sql.SQLException:[SQLITE_ERROR] SQL错误或缺少数据库(“ID”附近:语法错误)

时间:2015-11-22 20:46:48

标签: java swing sqlite user-interface sql-insert

我正在尝试插入以下数据,但是当我按下保存按钮时,会显示以下错误:java.sql.SQLException:[SQLITE_ERROR] SQL错误或缺少数据库(“ID”附近:语法错误)

感谢帮助=)

JButton btnSave = new JButton("Save");
    btnSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                String query="INSERT INTO PatientInfo (Patient ID, First Name, Last Name, Date of Birth, Address, Emergency Phone Number, Medical Condition, Appointments, Milling, Comments) values (?,?,?,?,?,?,?,?,?,?)";
                preparedstatement=connection.prepareStatement(query);
                preparedstatement.setString(1, patientIDtextField.getText());
                preparedstatement.setString(2, firstNametextField.getText());
                preparedstatement.setString(3, lastNametextField.getText());
                preparedstatement.setString(4, dobtextField.getText());
                preparedstatement.setString(5, addresstextField.getText());
                preparedstatement.setString(6, EPNtextField.getText());
                preparedstatement.setString(7, MedicalContextField.getText());
                preparedstatement.setString(8,ApptextField.getText());
                preparedstatement.setString(9, BillingtextField.getText());
                preparedstatement.setString(10, CommentstextField.getText());

                preparedstatement.executeQuery();
                JOptionPane.showMessageDialog(null, "Data Saved");


            } catch (Exception e1) {
                JOptionPane.showMessageDialog(null, e1);
            }
            finally{
                try{
                    preparedstatement.close();
                }
                catch(Exception e1){
                    JOptionPane.showMessageDialog(null, e1);
                }
            }
        }
    });

1 个答案:

答案 0 :(得分:1)

这里有一个空格Patient ID,其他列名也是。{那就是问题所在。如果您的列名称确实包含空格,您应该以某种方式限定它们:例如"。所以你应该试试"Patient ID"