@Override public boolean edit(Object o) { Caracteristica catacteristica = (Caracteristica) o; try { PreparedStatement query = connection.prepareStatement( "update Caracteristica set marca=?, modelo=?, numSerie=?, costo=?, moneda=? where idCaracteristica=?"); query.setString(1, catacteristica.getMarca()); query.setString(2, catacteristica.getModelo()); query.setString(3, catacteristica.getNumSerie()); query.setDouble(4, catacteristica.getCosto()); query.setString(5, catacteristica.getMoneda()); query.setInt(6, catacteristica.getIdCaracteristica()); query.execute(); query.close(); return true; } catch (Exception ex) { System.err.println(ex); return false; } }
@Override public boolean add(Object o) { Caracteristica catacteristica = (Caracteristica) o; try { PreparedStatement query = connection.prepareStatement( "insert into Caracteristica (marca, modelo, numSerie, costo, moneda) values (?,?,?,?,?)"); query.setString(1, catacteristica.getMarca()); query.setString(2, catacteristica.getModelo()); query.setString(3, catacteristica.getNumSerie()); query.setDouble(4, catacteristica.getCosto()); query.setString(5, catacteristica.getMoneda()); query.execute(); query.close(); return true; } catch (Exception ex) { System.err.println(ex); return false; } }
@Override public Object find(Integer id) { Caracteristica caracteristica = null; try { PreparedStatement query = connection.prepareStatement( "select * from Caracteristica where idCaracteristica = " + id); ResultSet rs = query.executeQuery(); if (rs.next()) { caracteristica = new Caracteristica(); caracteristica.setIdCaracteristica(rs.getInt(1)); caracteristica.setMarca(rs.getString(2)); caracteristica.setModelo(rs.getString(3)); caracteristica.setNumSerie(rs.getString(4)); caracteristica.setCosto(rs.getDouble(5)); caracteristica.setMoneda(rs.getString(6)); } query.close(); return caracteristica; } catch (Exception ex) { System.err.println(ex); return caracteristica; } }