表雇主
CREATE TABLE "Employer" ("employerID" INTEGER PRIMARY KEY NOT NULL ,
"name" CHAR,
"industry" CHAR,
"contact1" CHAR,
"contact2" CHAR,
"email" CHAR,
"website" CHAR,
"facts" CHAR,
"phone" VACHAR)
表作业
CREATE TABLE "Job" ("jobID" INTEGER PRIMARY KEY NOT NULL ,
"employerID" INTEGER,
"title" CHAR,
"description" CHAR,
"type" CHAR,"salary" CHAR,
"benefits" CHAR,
"vacancies" INTEGER,
"closing" CHAR,
"requirement" CHAR,
"placement" BOOL,
"applyTo" CHAR,
"status" CHAR,
"posted" CHAR,
"location" CHAR)
try {
//String sqlStm = "INSERT INTO Job (employerID,title,description,type,salary,benefits,vacancies,closing,requirement,placement,applyTo,status,posted,location) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) INNER JOIN Employer ON Job.employerID = Employer.employerID";
String sqlStm = "SET @SELECTED_ID = (SELECT employerID FROM Employer WHERE name = '"+comboEmployer.getSelectedItem().toString()+"') INSERT INTO Job (employerID,title,description,type,salary,benefits,vacancies,closing,requirement,placement,applyTo,status,posted,location)VALUES (@SELECTED_ID,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pst = conn.prepareStatement(sqlStm);
pst.setString(2,txtTitle.getText());
pst.setString(3,areaDescription.getText());
pst.setString(4,comboType.getSelectedItem().toString());
pst.setString(5,txtSalary.getText());
pst.setString(6,areaBenefits.getText());
pst.setString(7,txtVac.getText());
pst.setString(8,txtDate.getDateFormatString().toString());
pst.setString(9,areaReq.getText());
pst.setString(10,comboPlace.getSelectedItem().toString());
pst.setString(11,txtWeb.getText());
pst.setString(12,comboStatus.getSelectedItem().toString());
pst.setString(13,"01-01-2013");
pst.setString(14,txtLoc.getText());
pst.executeUpdate();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,e);
} finally {
try {
rs.close();
pst.close();
} catch (Exception e) {
}
}
}
我试图允许用户向系统添加工作,并且表单要求他们从Employer
表中选择雇主。我不确定如何将所选雇主与JCombobox
工作联系起来。即Job
表中的employerID 应与employer
表的employerID 匹配。我设法做到了Select
声明,
sql = "SELECT Job.jobID as 'Job ID', Employer.name as'Company', Job.title as 'Role', Job.type as 'Type', Job.closing as 'Closing Date' FROM Job INNER JOIN Employer ON Job.employerID=Employer.employerID ORDER BY Employer.name";
但不确定如何INSERT
进入 sqlite 管理器。继承人的形式: