示例#1
0
 public Produto(int idiproduto) {
   Connection conn = DbAccess.getConnection();
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   String sql =
       " select idiproduto,nmscompleto,dssdescricao,iditipoproduto,"
           + " vldvenda,opsativo from produto where idiproduto = ?";
   try {
     pstmt = conn.prepareStatement(sql);
     pstmt.setInt(1, idiproduto);
     rs = pstmt.executeQuery();
     if (rs.next()) {
       this.idiproduto = rs.getInt(1);
       this.nmscompleto = rs.getString(2);
       this.dssdescricao = rs.getString(3);
       this.iditipoproduto = rs.getInt(4);
       this.vldvenda = rs.getDouble(5);
       this.opsativo = rs.getString(6);
     } else {
       this.idiproduto = -1;
       this.nmscompleto = "";
       this.dssdescricao = "";
       this.iditipoproduto = -1;
       this.vldvenda = 0d;
       this.opsativo = "";
     }
   } catch (SQLException s) {
     s.printStackTrace();
     this.idiproduto = -1;
     this.nmscompleto = "";
     this.dssdescricao = "";
     this.iditipoproduto = -1;
     this.vldvenda = 0d;
     this.opsativo = "";
   } finally {
     try {
       if (null != rs) {
         rs.close();
       }
       if (null != pstmt) {
         pstmt.close();
       }
       DbAccess.closeConnection(conn);
     } catch (SQLException s) {
       s.printStackTrace();
       this.idiproduto = -1;
       this.nmscompleto = "";
       this.dssdescricao = "";
       this.iditipoproduto = -1;
       this.vldvenda = 0d;
       this.opsativo = "";
     }
   }
 }
示例#2
0
 public static Produto getProduto(int idiproduto) {
   Connection conn = DbAccess.getConnection();
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   String sql =
       " select produto.idiproduto,"
           + " produto.nmscompleto,produto.dssdescricao,"
           + " produto.iditipoproduto, produto.vldvenda,produto.opsativo,"
           + " produto.nmsimagem,"
           + " tipoproduto.nmscompleto "
           + " from produto "
           + " left outer join tipoproduto on tipoproduto.iditipoproduto = produto.iditipoproduto "
           + " where idiproduto = ? ";
   try {
     pstmt = conn.prepareStatement(sql);
     pstmt.setInt(1, idiproduto);
     rs = pstmt.executeQuery();
     if (rs.next()) {
       return new Produto(
           rs.getInt(1),
           rs.getString(2),
           rs.getString(3),
           (null != rs.getObject(4) ? rs.getInt(4) : -1),
           rs.getDouble(5),
           rs.getString(6),
           (null != rs.getObject(7) ? rs.getString(7) : ""),
           (null != rs.getObject(8) ? rs.getString(8) : ""));
     } else {
       return new Produto();
     }
   } catch (SQLException s) {
     s.printStackTrace();
     return new Produto();
   } finally {
     try {
       if (null != rs) {
         rs.close();
       }
       if (null != pstmt) {
         pstmt.close();
       }
       DbAccess.closeConnection(conn);
     } catch (SQLException s) {
       s.printStackTrace();
       return new Produto();
     }
   }
 }
示例#3
0
  public List getListaTiposProdutos() {
    Connection conn = DbAccess.getConnection();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    List lista = new ArrayList();
    String sql =
        " select tipoproduto.iditipoproduto, tipoproduto.nmscompleto"
            + " from tipoproduto "
            + " order by 2";

    try {
      pstmt = conn.prepareStatement(sql);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        List row = new ArrayList();
        row.add(rs.getObject(1));
        row.add(rs.getObject(2));
        lista.add(row);
      }
    } catch (SQLException s) {
      s.printStackTrace();
    } finally {
      try {
        if (null != rs) {
          rs.close();
        }
        if (null != pstmt) {
          pstmt.close();
        }
        DbAccess.closeConnection(conn);
      } catch (SQLException s) {
        s.printStackTrace();
      }
    }
    return lista;
  }
示例#4
0
  public List getListaProdutos(
      String tipoproduto, String nomeproduto, String ordenacao, String promocao) {
    Connection conn = DbAccess.getConnection();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    List lista = new ArrayList();
    String sql =
        " select produto.idiproduto, "
            + " produto.nmscompleto,produto.dssdescricao,"
            + " produto.iditipoproduto, produto.vldvenda,produto.opsativo,"
            + " produto.nmsimagem,"
            + " tipoproduto.nmscompleto "
            + " from produto "
            + " left outer join tipoproduto on tipoproduto.iditipoproduto = produto.iditipoproduto "
            + " where opsativo = 'S' ";
    if (!"".equals(tipoproduto)) {
      sql += " and tipoproduto.iditipoproduto in (" + tipoproduto + ")";
    }
    if (!"".equals(nomeproduto)) {
      sql += " and upper(produto.nmscompleto) like '%" + nomeproduto.toUpperCase().trim() + "%'";
    }
    if (!"".equals(promocao)) {
      sql += " and opspromocao = '" + promocao + "'";
    }

    if (!"".equals(ordenacao)) {
      sql += " order by 8," + ordenacao;
    } else {
      sql += " order by 8,2";
    }

    try {
      pstmt = conn.prepareStatement(sql);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        lista.add(
            new Produto(
                rs.getInt(1),
                rs.getString(2),
                rs.getString(3),
                (null != rs.getObject(4) ? rs.getInt(4) : -1),
                rs.getDouble(5),
                rs.getString(6),
                (null != rs.getObject(7) ? rs.getString(7) : ""),
                (null != rs.getObject(8) ? rs.getString(8) : "")));
      }
    } catch (SQLException s) {
      s.printStackTrace();
    } finally {
      try {
        if (null != rs) {
          rs.close();
        }
        if (null != pstmt) {
          pstmt.close();
        }
        DbAccess.closeConnection(conn);
      } catch (SQLException s) {
        s.printStackTrace();
      }
    }
    return lista;
  }