部分代码: …… public void actionPerformed(ActionEvent e){ // TODO Auto-generated method stub String diseaseTypeName=texUserName.getText(); textnew Disease=new textnew(); Disease.setDiseaseName(diseaseTypeName); CRUDnew se=new CRUDnew(); textnew sc=(textnew)box.getSelectedItem(); System.out.println(sc.getDiseaseTypeName()); if(e.getSource()==bnt){ if(se.useone(Disease)>0){ JOptionPane.showConfirmDialog(null,"增加成功" ); frame.setVisible(false); new Jmenustyle(); } } else if(e.getSource()==bnt1){ frame.setVisible(false); …… 添加数据代码: public static int useone(textnew Disease){ //增加 int i=0; String sql="insert into Disease values ('"+Disease.getDiseaseId()+"','"+Disease.getDiseaseTypeName()+"')"; conn=Datebaseone.info(); try{ PreparedStatement ps = conn.prepareStatement(sql); i=ps.executeUpdate(); }catch(Exception es){ System.out.println(es.toString()); } return i; } 错误提示: 流感 java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]INSERT 语句与 FOREIGN KEY 约束"FK__Disease__Disease__145C0A3F"冲突。该冲突发生于数据库"treatment",表"dbo.DiseaseType", column 'DiseaseTypeId'。
相关分类