避免在程序周围的JTextField的setText重复
下面是一个方法,它将 SQlite
中的Jobs显示到一个表上,并将它们设置为 labelText
。
Here is a method which displays Jobs from SQlite
onto a table and sets them as labelText
appropriately.
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(....)方式单独操作,有没有任何技巧,做得更短?任何好的简单的技术,可能重用上述代码,以尽量减少重复。
I want to be able to now allow users to select the Job (clicked row on table) to allow editing for update of data. So i provide a form to do that, instead of repeating lines such as descriptionArea.setText(rs.getString(5));
for Form textfields, is there a shorter way of doing this. or does each JTextfield
have to be individually manipulated using textfieldName.setText(....) way, is there any tricks to do it shorter? any nice easy techniques to perhaps reuse the above code to minimise repetition.
您可能需要查看Apache Commons DbUtils
,它使用 类文字作为运行时类型令牌和 ResultSetMetaData
来简化JDBC的一些较繁琐的部分。
You might want to look at the Apache Commons DbUtils
, which uses Class Literals as Runtime-Type Tokens and ResultSetMetaData
to simplify some of the more tedious parts of JDBC.