表 雇用主
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は、テーブルのemployerIDと一致する必要がありemployer
ます。私はなんとか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マネージャーへの入り方がわかりません。フォームは次のとおりです。