如何使用jtable第一列中的复选框显示从数据库到jtable的数据? [英] How to show data from database to jtable with checkboxes in the first column in jtable?

查看:125
本文介绍了如何使用jtable第一列中的复选框显示从数据库到jtable的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何填充jtable,并且我已经为上面的代码准备了可以正常工作的代码.但是问题在于它正在另一个项目中运行,但在我当前的项目中却是机器人.这两个项目的代码是相同的.这里是代码... purchaswtab是已经使用swing面板创建的表名.并且,在项目主文件"的退出按钮的情况下执行此功能. 定义数组ap的数组元素是因为我必须从结果集中的给定位置获取它们.

I know how to populate jtable and i had prepared the code for the above which works fine. But the problem is that it is working in another project but bot in my current project. The code for both the project is same. Here is the code... purchaswtab is the table name which has been already created using swing palette. And this function is executed in the event of the exit button of the Item Master. the array elements of an array ap are defined as i have to fetch them from the given position from the resultset.

public void populatetable(ItemMaster imm)
{
    imm.dispose();
    String t[][]=new String [30][10];
    int[] ap={19,1,2,4,18,16,17};
    Object[] h1=new Object[7];
    String a1,a2;
    int j=0,i=1;
    int len=0;
    try
     {            
        st=fun.connect1();           

        String query="select * from Temp_Purchase";
        ResultSet rs=st.executeQuery(query);       

        ResultSetMetaData rsmd=rs.getMetaData();

        while(rs.next())
        {
            int k=0;
            for(i=1;i<=7;i++,k++ )
            {
                t[j][i-1]=rs.getString(ap[k]);
                System.out.println(t[j][i-1]);
            }
            j++;
            len++;
        }

        fun.close();
     }
    catch(Exception e)
    {
        fun.close();
        System.out.println("Exception:"+e);
    }

    DefaultTableModel de=(DefaultTableModel)purchaseTab.getModel();
    purchaseTab=new JTable(de);



    //Code for filling data into table

    for(i=0;i<len;i++)
    {
        for(j=1;j<=7;j++)
        {                
            h1[j-1]=t[i][j-1];
        }

        if(h1[0]=="0")
        {         
            h1[0]=Boolean.FALSE;         
        }
        de.insertRow(i,h1);            
    }
    //jsp.setViewportView(Table);
}

推荐答案

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