Search code examples
javaswingjtable

jtable how to use rs2xml


I'am currently newbie at java, and I've been searching for a effective way to put database informations to jtable and I heard about rs2xml. I really want to learn this because other methods makes me confuse and gives me headache.

Does anyone know how to use it effectively ? And if you don't mind can you explain with a simple code.

Thanks in advance.


Solution

  • import net.proteanit.sql.DbUtils;
    
    
    
    //..and somewhere in your code
    try {
        st = conn.createStatement();
        st.executeQuery(q);
        ResultSet rs = st.executeQuery(q);
    
        // here is where library is used
        jTable1.setModel(DbUtils.resultSetToTableModel(rs)); 
        //               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex);
    } finally {
        try {
            rs.close();
        } catch (SQLException e) {
            /* ignore */ 
        }
    
        try {
            st.close();
        } catch (SQLException e) {
            /* ignore */ 
        }
    }
    

    that a sample of use video tutorial