避免在程序周围的JTextField的setText重复 [英] Avoiding JTextField setText repetition around the program

查看:226
本文介绍了避免在程序周围的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.

这篇关于避免在程序周围的JTextField的setText重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆