Retrieving Data from JDBC Database into Jtable

后端 未结 6 1674
长情又很酷
长情又很酷 2020-12-16 07:57

Hi I have successfully linked my jTable to JDBC database. However, I am having trouble retrieving them. I want the saved data to appear when I restart the program but it is

6条回答
  •  鱼传尺愫
    2020-12-16 08:33

    First create the table model then use that fetch_data() function. Make sure your database connection is working. Call the function in main constructor. That's it.

    DefaultTableModel dm;
    
    dm=(DefaultTableModel) jTable1.getModel();
    
    public void fetch_data(){
    
        try{
            String sql= "select * from tbl_name";
            ResultSet rs=st.executeQuery(sql);
            YourjTableName.setModel(DbUtils.resultSetToTableModel(rs));
        }catch(Exception e){
            System.out.println(e);
        }
    }
    

提交回复
热议问题