public void updateMarcas(MarcaVo marcaVo) throws Exception { Connection connection = null; PreparedStatement ps = null; StringBuilder qry = new StringBuilder(); int i = 1; try { connection = getConnection(); qry.append(" UPDATE marca set "); qry.append(" nm_marca = ? "); qry.append(" WHERE cd_marca = ? "); ps = connection.prepareStatement(qry.toString()); ps.setString(i++, marcaVo.getDescricao()); ps.setInt(i++, Integer.parseInt(marcaVo.getCodigoMarca())); ps.execute(); } catch (SQLException e) { e.printStackTrace(); } finally { releaseResouces(connection, ps); } }
public void insertMarcas(MarcaVo marcaVo) throws Exception { Connection connection = null; PreparedStatement ps = null; StringBuilder qry = new StringBuilder(); int i = 1; try { connection = getConnection(); qry.append(" INSERT INTO marca "); qry.append(" ( rowid, "); qry.append(" cd_marca, "); qry.append(" cd_empresa, "); qry.append(" nm_marca ) "); qry.append(getValues(qry)); ps = connection.prepareStatement(qry.toString()); ps.setString(i++, getNovaSimulacaoRowid()); ps.setInt(i++, Integer.parseInt(marcaVo.getCodigoMarca())); ps.setInt(i++, Integer.parseInt(marcaVo.getCodigoEmpresa())); ps.setString(i++, marcaVo.getDescricao()); ps.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { releaseResouces(connection, ps); } }
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; }