Gente to com um problema meio estranho aqui!
É assim, eu tenho uma JTable e dela eu adiciono, excluo e altero registos do BD (PostGresql), tudo funciona direitinho, mas quando eu excluo um registro da tabela se eu inserir um logo após este não é adicionado no banco, codigo abaixo:
Botão excluir
private void btnExcluiActionPerformed(java.awt.event.ActionEvent evt) {
if(tabelaTeste.getSelectedRow()!= -1){
gt.excluiRegistro("DELETE FROM teste WHERE proximo = "+ modelo.getValueAt(tabelaTeste.getSelectedRow(), 0) + ";");
modelo.removeRow(tabelaTeste.getSelectedRow());
}
else{
JOptionPane.showMessageDialog(null, "Uma linha da tabela deve estar selecionada","Cuidado", JOptionPane.WARNING_MESSAGE);
}
}
Botão Sair (Faz alterações no BD)
private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {
String[] tabela = new String[3];
String matriz [][] = new String[10][3];
try{
for(int j = 0; j < tabelaTeste.getRowCount()-1; j++){
for(int i = 0; i < tabelaTeste.getColumnCount(); i++){
tabela[i] = (String) tabelaTeste.getValueAt(j, i);
}
for(int k = 0; k < tabelaTeste.getColumnCount(); k++){
matriz[j][k] = tabela[k];
}
}
}
catch(NullPointerException npe){
npe.printStackTrace();
}
String colNome = "";
String colLP = "";
String colProx = "";
try{
rs.last();
int linhasNoBD = rs.getRow();
if(linhasNoBD != 0){
rs.first();
}
if((tabelaTeste.getRowCount() -1) == 0){
this.dispose();
return;
}
for(int i = 0; i < linhasNoBD; i++){
if(rs.getString(1).equalsIgnoreCase(matriz[i][0])){ // Alterar
colProx = matriz[i][0];
colNome = matriz[i][1];
colLP = matriz [i][2];
gt.alteraRegistro("UPDATE teste SET Nome = '"+colNome+"', Linguagem = '"+colLP+"' WHERE Proximo = '"+colProx+"';");
}
rs.next();
}
if(linhasNoBD < tabelaTeste.getRowCount()){ // Adicionar e tentando naum dar ioobe
for(int j = linhasNoBD; j < tabelaTeste.getRowCount()-1; j++){
colNome = matriz[j][1];
colLP = matriz[j][2];
gt.adicionaRegistro("INSERT INTO teste (Nome, Linguagem) VALUES ('"+colNome+"', '"+colLP+"');");
}
}
}
catch (SQLException sqle){
sqle.printStackTrace();
}
catch(NullPointerException npe){
npe.printStackTrace();
}
this.dispose();
}
Se puderem me ajudar agradeço muito! =D