fiz minha tabela assim
private void tabela1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int indexrow= tabela1.getSelectedRow();
DefaultTableModel model = (DefaultTableModel)tabela1.getModel();
id=model.getValueAt(indexrow, 0).toString();
campoclasse.setText(model.getValueAt(indexrow, 1).toString());
camposetor.setText(model.getValueAt(indexrow, 2).toString());
}
mas ao adicionar um novo objeto a tabela com o botao criar, o jtable nao atualizar, os dados são criados no banco de dados mas só atualiza o jtable se eu fechar e abrir novamente
private void btncriarActionPerformed(java.awt.event.ActionEvent evt) {
try {
// TODO add your handling code here:
PreparedStatement pst= conecta.con.prepareStatement("insert into classe (classe,setor) values(?,?) ");
pst.setString(1, campoclasse.getText());
pst.setString(2, camposetor.getText());
pst.executeUpdate();
JOptionPane.showMessageDialog(rootPane, "Criado com sucesso!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(rootPane, "Erro na inserção!\n Erro: "+ex);
}
}
PRINTS EM ORDEM: