Boa tarde galera, sempre quando atualizo os dados, eles vão para a ultima posição da JTable… por que???
Vo postar meus códigos fontes referentes a alteração…Vlw
MÉTODO ALTERAR DO DAO
[code]public void altera(Contato contato) throws SQLException{
Connection conn = Conexao.getConexao();
String sql = " Update usuario set nome = ? ,idade = ? ,telefone = ? where idusuario = ? ";
PreparedStatement stmt = conn.prepareStatement(sql);
// Setar os valores no statemant
stmt.setString(1, contato.getNome());
stmt.setString(2, contato.getIdade());
stmt.setString(3, contato.getTelefone());
stmt.setInt(4,contato.getIdusuario());
// Executa o código SQL com os valores setados
stmt.execute();
stmt.close();[/code]
METODO ALTERAR DA REGRA DE NEGOCIO
[code]public void alterarContato(int idusuario,String nome,String idade,String telefone) throws SQLException{
Contato cont = new Contato(nome,idade,telefone);
cont.setIdusuario(idusuario);
contatoDAO cDAO = new contatoDAO();
cDAO.altera(cont);
}[/code]
EVENTO DO MOUSE, PARA LISTAR OS DADOS NOS TEXTFIELDS
private void tabelaMouseClicked(java.awt.event.MouseEvent evt) {
int linha = tabela.getSelectedRow();
tf_id.setText(tabela.getValueAt(linha, 0).toString());
tf_nome.setText(tabela.getValueAt(linha, 1).toString());
tf_idade.setText(tabela.getValueAt(linha, 2).toString());
tf_telefone.setText(tabela.getValueAt(linha, 3).toString());
}
BOTAO ALTERAR
[code] private void bt_alterarActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource() == bt_alterar){
ContatoNegocio cont = new ContatoNegocio();
try {
cont.alterarContato(Integer.parseInt(tf_id.getText()), tf_nome.getText(), tf_idade.getText(), tf_telefone.getText());
} catch (SQLException ex) {
Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
}
}
} [/code]
SEMPRE QUE ALTERO OS DADOS DA JTALE, ELES VAO PARA A ULTIMA POSIÇÃO…VLW