예제 #1
0
 @Override
 public boolean update(Gasto gasto, int id) throws DAOException {
   String sql = "UPDATE gastos SET idDespesa=?,valor=?,data=?,idSecretaria=? WHERE idGasto=?;";
   Connection con = null;
   PreparedStatement ps = null;
   int retorno = 0;
   try {
     con = MyConnection.init();
     ps = con.prepareStatement(sql);
     ps.setInt(1, gasto.getIdDespesa());
     ps.setDouble(2, gasto.getValor());
     ps.setDate(3, (java.sql.Date) gasto.getData());
     ps.setInt(4, gasto.getIdSecretaria());
     ps.setInt(5, id);
     retorno = ps.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DAOException(e, "ERRO! UPDATE na TABELA GASTOS. DATA(" + new Date() + ")");
   } finally {
     MyConnection.closeConnection(con, ps);
   }
   return retorno == 0 ? false : true;
 }
예제 #2
0
 @Override
 public boolean insert(Gasto gasto) throws DAOException {
   String sql =
       "INSERT INTO gastos(idGasto,idDespesa,valor,data,idSecretaria) VALUES (null,?,?,?,?);";
   Connection con = null;
   PreparedStatement ps = null;
   int retorno;
   try {
     con = MyConnection.init();
     ps = con.prepareStatement(sql);
     ps.setInt(1, gasto.getIdDespesa());
     ps.setDouble(2, gasto.getValor());
     ps.setDate(3, (java.sql.Date) gasto.getData());
     ps.setInt(4, gasto.getIdSecretaria());
     retorno = ps.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DAOException(e, "ERRO! INSERT na TABELA GASTOS. DATA(" + new Date() + ")");
   } finally {
     MyConnection.closeConnection(con, ps);
   }
   return retorno == 0 ? false : true;
 }