Java & Netbeans: Load data from jTable selected row to jTextfield

The code is use for loading data from jTable selected row and send it to jTextfield, jCombobox, and jDateChooser.

1.Use jTable event click and insert the code below.

try{
    int row=jTable1.getSelectedRow();
    String num  = (jTable1.getModel().getValueAt(row, 0).toString());
    String sql="SELECT * FROM tablename";
    pst=conn.prepareStatement(sql);
    rs = pst.executeQuery(sql);
    while(rs.next())
    {
        jTextfield1.setText(rs.getString("column1"));
        jTextfield2.setText(rs.getString("column2"));
    }
}catch(Exception e) {
    JOptionPane.showMessageDialog(this, e.getMessage());
}

 

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz