CREATE TABLE "Employer" (
"employerID" INT PRIMARY KEY NOT NULL,
"name" CHAR,
"industry" CHAR,
"contact1" CHAR,
"contact2" CHAR,
"email" CHAR,
"website" CHAR,
"facts" CHAR,
"phone" VACHAR
)
CREATE TABLE "Job" (
"jobID" INT PRIMARY KEY NOT NULL,
"employerID" INT,
"title" CHAR,
"description" CHAR,
"type" CHAR,
"salary" CHAR,
"benefits" CHAR,
"vacancies" INT,
"closing" CHAR,
"requirement" CHAR,
"placement" BOOL,
"applyTo" CHAR,
"notes" CHAR,
FOREIGN KEY (employerID) REFERENCES Employer(employerID)
)
我正在寻找从数据库中获取值并将它们设置为文本,但是当涉及到键JLabel
时我不确定 sql 语句。foreign
SQL 语句应该是表中的SELECT
所有值,Job
除了employerID
并使用外键employerID
来获取name
公司的值...可以告诉我正确的 sql 语句。我想显示如下示例的信息:
分析师 - 微软
JobID: 4545454 描述: Good job email: 123@hotmail.com 电话: 45545
但不确定如何显示 MICROSOFT
public void setText() {
try {
String sql = "SELECT a.*, b.name FROM Employer a INNER JOIN `Job` b ON a.employerID = b.employerID";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while (rs.next()) {
System.out.println(rs.getString(1)); //how Do i Print the name value from Employer table??
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
System.out.println(rs.getString(5));
System.out.println(rs.getString(6));
}
}
如何打印name
EMployer 表中的值以及 Job 表中的所有数据?