0

我有以下课程:

public class customer_master extends javax.swing.JInternalFrame {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    JFrame parent;
    public customer_master(JFrame parent) {

        this.parent=parent;
        initComponents();

        try {
            String qry="select customer_code, customer_name, customer_address, customer_created_time from customer";
            database.JavaConnect jc= new JavaConnect(); 
            con = jc.ConnectDB();
            ps = con.prepareStatement(qry);
            rs = ps.executeQuery();
            jTable1.setModel(DbUtils.resultSetToTableModel(rs));
            con.close();
        }
        catch(SQLException e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }    
}

它还更改了列的名称,但如果有人可以提供帮助,我想在不更改列名称的情况下添加 rs。提前致谢。

4

2 回答 2

1

您的问题意味着您正在使用新的 ResultSet 重新刷新和现有 JTable。因此,当您第一次创建 JTable 并为您需要添加的每一列分配名称时:

JTable table = new JTable(...);
table.setAutoCreateColumnsFromModel( false );

这将告诉表不要重新创建 TableColumnModel,因此所有列和自定义渲染器和编辑器都将保留。

于 2013-02-16T16:11:57.810 回答
0

只需更改您的查询

String qry="select customer_code, customer_name, customer_address, customer_created_time from customer";

String qry="select customer_code AS Customer Code , customer_name AS Customer Name , customer_address AS Customer Address , customer_created_time AS DOJ from customer";

你会很高兴的。

于 2019-05-28T10:12:04.107 回答