예제 #1
0
파일: MarcaDao.java 프로젝트: psergio81/CET
  public List<MarcaVo> getListaMarcas(MarcaVo marcaVo, boolean filtrar) {

    Connection connection = null;
    ResultSet rs = null;
    PreparedStatement ps = null;
    StringBuilder qry = new StringBuilder();
    List<MarcaVo> marcasList = null;
    int i = 1;

    try {

      connection = getConnection();

      qry.append("SELECT rowid, cd_marca, nm_marca FROM marca ");
      qry.append(" where cd_empresa = ? ");

      if (filtrar) {
        qry.append(" and nm_marca like '%' ? '%' ");
      }

      ps = connection.prepareStatement(qry.toString());
      ps.setInt(i++, UtConverte.stringToInteiro(marcaVo.getCodigoEmpresa()));

      if (filtrar) {
        ps.setString(i++, marcaVo.getDescricao());
      }

      rs = ps.executeQuery();

      marcasList = new ArrayList<MarcaVo>();

      while (rs.next()) {
        marcaVo = new MarcaVo();
        marcaVo.setRowid(rs.getString("rowid"));
        marcaVo.setCodigoMarca(String.valueOf(rs.getInt("cd_marca")));
        marcaVo.setDescricao(rs.getString("nm_marca"));
        marcasList.add(marcaVo);
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      releaseResouces(connection, ps, rs);
    }

    return marcasList;
  }
예제 #2
0
파일: MarcaDao.java 프로젝트: psergio81/CET
  private MarcaVo getMarca(MarcaVo marcaVo, int criterio) {

    Connection connection = null;
    ResultSet rs = null;
    PreparedStatement ps = null;
    StringBuilder qry = new StringBuilder();
    int i = 1;

    try {

      connection = getConnection();

      qry.append(" SELECT rowid, cd_marca, cd_empresa, nm_marca FROM marca ");
      qry.append(" where cd_empresa = ? ");
      qry.append(" and cd_marca = ? ");

      ps = connection.prepareStatement(qry.toString());
      ps.setInt(i++, UtConverte.stringToInteiro(marcaVo.getCodigoEmpresa()));
      ps.setInt(i++, UtConverte.stringToInteiro(marcaVo.getCodigoMarca()));

      rs = ps.executeQuery();

      marcaVo = null;

      if (rs.next()) {
        marcaVo = new MarcaVo();

        marcaVo.setRowid(rs.getString("rowid"));
        marcaVo.setCodigoMarca(rs.getString("cd_marca"));
        marcaVo.setCodigoEmpresa(rs.getString("cd_empresa"));
        marcaVo.setDescricao(rs.getString("nm_marca"));
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      releaseResouces(connection, ps, rs);
    }

    return marcaVo;
  }