Duvida de como excluir

6 respostas
G

Boa tarde,
estou na duvida de como posso fazer para pegar e conseguir que exclue da tabela somente se excluir do banco. pensei em fazer o dao retornar true ou false mas nao sei como q vo fazer o codigo reconhecer isso se alguem puder me ajudar

Application a = new Application(); int indexes[] = table.getSelectionIndices(); for (int i = 0; i < indexes.length; i++) { a = dao.getAplication(Integer.parseInt(table.getItem(indexes[i]).getData( table.getItem(indexes[i]).getText()).toString())); dao.delete(a); } table.remove(indexes); table.update(); table.setCursor(new Cursor(getSite().getShell().getDisplay(),SWT.CURSOR_ARROW)); }

6 Respostas

B

No método delete da sua DAO, você utiliza um try/catch.

public boolean delete(int param) {
try {
...
//Seu código
} catch(Exception e) {
return false;
}
return true;
}

Aí no método que chama este delete:

boolean excluido = dao.delete(a); id (excluido) { //atualiza a tabela }

G

biro:
No método delete da sua DAO, você utiliza um try/catch.

public boolean delete(int param) {
try {
...
//Seu código
} catch(Exception e) {
return false;
}
return true;
}

Aí no método que chama este delete:

boolean excluido = dao.delete(a); id (excluido) { //atualiza a tabela }

brigadao cara mas o seguinte eu num excluo linha por linha nao… e sim varias linhas =x

abelgomes
Application a = new Application();  
                 int indexes[] = table.getSelectionIndices();  
                   for (int i = 0; i < indexes.length; i++) {  
                       a = dao.getAplication(Integer.parseInt(table.getItem(indexes[i]).getData(  
                                 table.getItem(indexes[i]).getText()).toString()));  
                      if( dao.delete(a)){
                            table.remove(i);  
                       }
 
                   }  
                      table.update();  
                  table.setCursor(new Cursor(getSite().getShell().getDisplay(),SWT.CURSOR_ARROW));  
                }

acho que assim vai…

G
abelgomes:
Application a = new Application();  
                 int indexes[] = table.getSelectionIndices();  
                   for (int i = 0; i < indexes.length; i++) {  
                       a = dao.getAplication(Integer.parseInt(table.getItem(indexes[i]).getData(  
                                 table.getItem(indexes[i]).getText()).toString()));  
                      if( dao.delete(a)){
                            table.remove(i);  
                       }
 
                   }  
                      table.update();  
                  table.setCursor(new Cursor(getSite().getShell().getDisplay(),SWT.CURSOR_ARROW));  
                }

acho que assim vai...

num da nao ele remove os indices anteriores... da uma bagunça danada

andreiribas

Ou converte a exception para uma mais conveniente, e faz o DAO lançar essa exception, então você controla isso no teu controller / service.

G

hmm e como eu faria isso ahuauha estou iniciando =x tipo criaria minha propria exception que faria o q?

Criado 10 de novembro de 2009
Ultima resposta 10 de nov. de 2009
Respostas 6
Participantes 4