开发者

Populate Java table with resultSet

I'm building a java application that gets its data from an oracle database and puts it into a JTable.

My problem is I am not able to populate the table, I don't understand how to do it. Javadoc is useless.

I don't understand why the table doesn't get the rows:

 if ((report.getMsg开发者_Go百科()=="selectEventoAll") && (report.getEsito()==1))
    {

        DefaultTableModel dtm = new DefaultTableModel();
        eventi_tb.setModel(dtm);

        try
        {
            ResultSet res_eventi = report.getRes();
            i = 0;
            Object[][] datiEventi = new Object[report.getRowCount()][5];

            while(res_eventi.next())
            {
               j = 0; 
               while (j < 5)
               {
                  datiEventi[i][j] = res_eventi.getObject(j+2);
                  j++;
               }
               dtm.addRow(datiEventi[i]);
               i++;
            }
        }


You can do this using a custom implementation of AbstractTableModel.

After you get your results back, put them in a list and let this be the backing list for your table model.

See here .. http://download.oracle.com/javase/tutorial/uiswing/components/table.html#data


Table From Database should get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜