Java & Netbeans: Load data from MySQL to jTable

The following code is use for loading data from MySQL database to jTable in your Netbeans project. You need to add a new jTable from pallets and assign a variable name for your jTable. Follow the steps below.

1.Crate a  new method inside your class and insert the code below

try{
    String sql="SELECT * FROM tablename";
    pst=conn.prepareStatement(sql);
    rs = pst.executeQuery(sql);
    jtablename.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e) {
    JOptionPane.showMessageDialog(this, e.getMessage());
}

2.Copy the method name and insert it into the public method after the “initcomponents();

3.Done!

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz