在swing中向现有表添加一列 [英] add a column to an existing Table in swing

查看:94
本文介绍了在swing中向现有表添加一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个swing应用程序,可以在其中使用rs2xml.jar从数据库中获取数据并将其显示在表中.

I am developing a swing application in which I can fetch the data from the database and display it in a table by using rs2xml.jar.

这是我的代码:

package swing_demo_app;

//import in.teamnet.utils.DbUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import net.proteanit.sql.DbUtils;

/**
 *
 * @author ankitparmar
 */
public class NewTable extends javax.swing.JFrame {

    /**
     * Creates new form NewTable
     */

    Connection conn=null;
    ResultSet rs=null;
    PreparedStatement pre=null;


    public NewTable() {
        initComponents();
        conn=DBEngine.getConnection();
        update_table();

    }
    private void update_table(){
        try {
            String sql="SELECT * FROM ierm.wcmap";
            pre=conn.prepareStatement(sql);
            rs=pre.executeQuery();
            Table.setModel(DbUtils.resultSetToTableModel(rs));
            Table.setRowSelectionAllowed(false);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

现在,我需要在此现有表中添加一列. 有人能指出我正确的方向吗?

Now, I need to add a column in this existing table.. Can any one point me to a right direction ?

推荐答案

我正在猜测

  • TableJTable
  • DbUtils.resultSetToTableModel(rs)返回TableModel或类似的内容.
  • Table is a JTable
  • DbUtils.resultSetToTableModel(rs) return a TableModel or similar.

获取数据库模型,但不要将其添加到表中

Get the model of the database, but don't add it to table

DefaultTableModel tableModel = DbUtils.resultSetToTableModel(rs);

在表格中添加新列

tableModel.addColumn(newColumnName);

并将模型设置为表格

jTable.setModel(tableModel);

这篇关于在swing中向现有表添加一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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