Most simple code to populate JTable from ResultSet

前端 未结 10 976
慢半拍i
慢半拍i 2020-11-22 11:22

I googled the whole day and no luck. I call getnPrintAllData() method after pressing OK button. So the code is:

public class DatabaseSQLiteConne         


        
10条回答
  •  -上瘾入骨i
    2020-11-22 12:04

    I think this is the Easiest way to populate/model a table with ResultSet.. Download and include rs2xml.jar Get rs2xml.jar in your libraries..

    import net.proteanit.sql.DbUtils;
    
        try
        {
        CreateConnection();
        PreparedStatement st =conn.prepareStatement("Select * from ABC;");
        ResultSet rs = st.executeQuery();
        tblToBeFilled.setModel(DbUtils.resultSetToTableModel(rs));
        conn.close();
        }
        catch(Exception ex)
        {
        JOptionPane.showMessageDialog(null, ex.toString());
        }
    

提交回复
热议问题