Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static <T> boolean cadastrar(T objeto) {
- if(objeto instanceof Pessoa)
- {
- System.out.println(con);
- Pessoa pe = (Pessoa)objeto;
- String sql = Sql.CADASTRAR_PESSOA;
- try {
- PreparedStatement stm = con.prepareStatement(sql);
- stm.setInt(1, pe.getCodigoPessoa());
- stm.setDate(2, pe.getDataAniversario());
- stm.setString(3, pe.getNome());
- stm.executeUpdate();
- return true;
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else if(objeto instanceof Email){
- Email email = (Email)objeto;
- String sql = Sql.CADASTRAR_EMAIL;
- try {
- PreparedStatement stm = con.prepareStatement(sql);
- stm.setInt(2, email.getCodigoPessoa());
- stm.setString(1, email.getEmail());
- stm.executeUpdate();
- return true;
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else if(objeto instanceof Tarefa){
- Tarefa tarefa = (Tarefa)objeto;
- String sql = Sql.CADASTRAR_TAREFA;
- try {
- PreparedStatement stm = con.prepareStatement(sql);
- stm.setInt(1, tarefa.getCodigoTarefa());
- stm.setString(2, tarefa.getDescrição());
- stm.setDate(3,tarefa.getData());
- stm.setTime(4, tarefa.getHora());
- stm.executeUpdate();
- return true;
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement