當前我正在從事醫院管理系統項目。我有兩張醫生和病人表,他們之間已經做了一個鏈接表訪問。醫生和患者表的主鍵分別是訪問表的外鍵。我可以從我的代碼更新醫生表。無論何時將記錄插入患者表格中,都要檢查醫生的表格,以確定是否存在分配的醫生,是否存在醫生並將插入插入到就診表格中。爲此,我在患者表上創建了一個觸發器。現在,無論何時嘗試註冊患者,患者表格都會更新,但代碼會拋出一個MySQLException
,並顯示消息「列數不匹配第1行處的值計數」。如何在多對多的關係鏈接表中插入記錄
代碼
this.stmt=this.mycon.createStatement();
String query_add_patient="insert into patients values ('"+nic+"','"+name+"','"+address+"','"+city+"',"+age+",'"+dob+"','"+telephone+"');";
String query_select_employees="select * from employees where employee_type='Doctor' and employee_qualification='"+doctor+"'";
ResultSet rs=this.stmt.executeQuery(query_select_employees);
if(!rs.next()) {
JOptionPane.showMessageDialog(this, "This Doctor is not available in this facility!!!","Admin Error",JOptionPane.ERROR_MESSAGE);
return false;
}
rs.first();
String pattern = "yyyy-m-d";
SimpleDateFormat format = new SimpleDateFormat(pattern);
String enic=rs.getString("employee_nic");
System.out.println(enic);
String query="insert into Visits (patient_nic,employee_nic) values ("+nic+","+enic+")";
this.stmt.executeUpdate(query_add_patient);
closeConnection();
openConnection();
this.stmt=mycon.createStatement();
this.stmt.executeUpdate(query);
return true;
這裏的聲明 「插入訪問」 導致的問題。我試圖關閉並再次打開連接,但沒有奏效。我的訪問表的結構是
訪問
patient_nic (varchar(45)) FK --> patient.patient_nic
employee_nic (varchar(45)) FK --> employee-->employee_nic
你檢查過表的定義和插入的值http://htmlfixit.com/cgi-tutes/tutorial_MySQL_Error_Invalid_Query_Column_Count_Does_Not_Match_Value_Count.php – Hitman47
是的,我已經做到了,但沒有工作!!! –