这是一种将工作从表格显示SQlite
到表格并进行labelText
适当设置的方法。
private void setLabelText() {
try {
String table_click0 = (table_job.getModel().getValueAt(row, 0).toString());
String sqlSt = "SELECT Employer.name, * FROM Job INNER JOIN Employer ON Job.employerID = Employer.employerID WHERE jobID='"+table_click0+"' ";
conn = JavaConnect.ConnectDB();
pst = conn.prepareStatement(sqlSt);
rs = pst.executeQuery();
if(rs.next()) {
descriptionArea.setText(rs.getString(5));
empTitLabel.setText(rs.getString(1)+" - "+rs.getString(4));
idLabel.setText("Job Reference: " + rs.getString(2));
typeLabel.setText("Job Type: " + rs.getString(6));
salaryLabel.setText("Salary: " + rs.getString(7));
benefitsLabel.setText("Benefits : " + rs.getString(8));
vacLabel.setText("Vacancies : " + rs.getString(9));
closeLabel.setText("Closing Date: " + rs.getString(10));
reqLabel.setText("Requirement : " + rs.getString(11));
placeLabel.setText("Placement : " + rs.getString(12));
applyToLabel.setText("Apply To: " + rs.getString(13));
statusLabel.setText("Job Status: "+rs.getString(14));
locLabel.setText("Location: "+rs.getString(16));
postedLabel.setText("Posted: "+rs.getString(15));
}
}
我希望现在能够允许用户选择作业(单击表上的行)以允许编辑以更新数据。因此,我提供了一个表单来执行此操作,而不是重复诸如descriptionArea.setText(rs.getString(5));
表单文本字段之类的行,是否有更短的方法来执行此操作。还是每个JTextfield
都必须使用 textfieldName.setText(....) 方式单独操作,是否有任何技巧可以缩短它?任何不错的简单技术,也许可以重用上述代码以尽量减少重复。