Advertisement
tadeuespindola

suporte-luiz-henrique-jdev-jdbc

Jun 22nd, 2023 (edited)
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | Help | 0 0
  1. public void deleteFonesPorUser(Long idUser) {
  2.     deleteFones(idUser);
  3.     deleteUser(idUser);
  4. }
  5.  
  6. private void deleteFones(Long idUser) {
  7.     try {
  8.         String fone = "DELETE FROM telefoneuser WHERE usuariopessoa = " + idUser;
  9.         PreparedStatement preparedStatement = connection.prepareStatement(fone);
  10.         preparedStatement.executeUpdate();
  11.         connection.commit();
  12.     } catch (Exception e) {
  13.         System.out.println(e);
  14.         try {
  15.             connection.rollback();
  16.         } catch (Exception e2) {
  17.             System.out.println(e2);
  18.         }
  19.     }  
  20. }
  21.  
  22. private void deleteUser(Long idUser) {
  23.     try {
  24.         String user = "DELETE FROM userposjava WHERE id = " + idUser;
  25.         PreparedStatement preparedStatement = connection.prepareStatement(user);
  26.         preparedStatement.executeUpdate();
  27.         connection.commit();
  28.     } catch (Exception e) {
  29.         System.out.println(e);
  30.         try {
  31.             connection.rollback();
  32.         } catch (Exception e2) {
  33.             System.out.println(e2);
  34.         }
  35.     }  
  36. }
Tags: Java jdev DAO JDBC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement