Advertisement
Juninhown02

Tipo generico

Jul 23rd, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. public static <T> boolean cadastrar(T objeto) {
  2.        
  3.         if(objeto instanceof Pessoa)
  4.         {
  5.             System.out.println(con);
  6.             Pessoa pe = (Pessoa)objeto;
  7.             String sql = Sql.CADASTRAR_PESSOA;
  8.             try {
  9.                 PreparedStatement stm = con.prepareStatement(sql);
  10.                 stm.setInt(1, pe.getCodigoPessoa());
  11.                 stm.setDate(2, pe.getDataAniversario());
  12.                 stm.setString(3, pe.getNome());
  13.                 stm.executeUpdate();
  14.                 return true;
  15.             } catch (SQLException e) {
  16.                 // TODO Auto-generated catch block
  17.                 e.printStackTrace();
  18.             }
  19.         }else if(objeto instanceof Email){
  20.             Email email = (Email)objeto;
  21.             String sql = Sql.CADASTRAR_EMAIL;
  22.             try {
  23.                 PreparedStatement stm = con.prepareStatement(sql);
  24.                 stm.setInt(2, email.getCodigoPessoa());
  25.                 stm.setString(1, email.getEmail());
  26.                 stm.executeUpdate();
  27.                 return true;
  28.             } catch (SQLException e) {
  29.                 // TODO Auto-generated catch block
  30.                 e.printStackTrace();
  31.             }
  32.         }else if(objeto instanceof Tarefa){
  33.             Tarefa tarefa = (Tarefa)objeto;
  34.             String sql = Sql.CADASTRAR_TAREFA;
  35.             try {
  36.                 PreparedStatement stm = con.prepareStatement(sql);
  37.                 stm.setInt(1, tarefa.getCodigoTarefa());
  38.                 stm.setString(2, tarefa.getDescrição());
  39.                 stm.setDate(3,tarefa.getData());
  40.                 stm.setTime(4, tarefa.getHora());
  41.                 stm.executeUpdate();
  42.                 return true;
  43.             } catch (SQLException e) {
  44.                 // TODO Auto-generated catch block
  45.                 e.printStackTrace();
  46.             }
  47.         }
  48.        
  49.         return false;
  50.        
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement