예제 #1
0
 @Override
 public boolean update(Estilo est) throws SQLException {
   boolean resul = false;
   if (est != null && !est.equals(new Estilo())) {
     DbConnection conn = new DbConnection();
     String sql =
         "UPDATE `estilo` SET `nombre`= ? , `descripcion`= ?, `codigo`= ? WHERE  `id`= ? ;";
     PreparedStatement consulta = conn.getConnection().prepareStatement(sql);
     consulta.setString(1, est.getNombre());
     consulta.setString(2, est.getDescripcion());
     consulta.setString(3, est.getCodigo());
     consulta.setInt(4, est.getId());
     if (consulta.executeUpdate() == 1) {
       resul = true;
     }
     cerrarPeticion(conn, consulta);
   }
   return resul;
 }
예제 #2
0
 @Override
 public int insert(Estilo est) throws SQLException {
   int resul = -1;
   if (est != null && !est.equals(new Estilo())) {
     DbConnection conn = new DbConnection();
     String sql = "INSERT INTO `estilo` (`nombre`,`descripcion`, `codigo` ) VALUES ( ?, ?, ? );";
     PreparedStatement consulta =
         conn.getConnection().prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
     consulta.setString(1, est.getNombre());
     consulta.setString(2, est.getDescripcion());
     consulta.setString(3, est.getCodigo());
     if (consulta.executeUpdate() == 1) {
       ResultSet generatedKeys = consulta.getGeneratedKeys();
       if (generatedKeys.next()) {
         resul = generatedKeys.getInt(1);
         est.setId(resul);
       }
     }
     cerrarPeticion(conn, consulta);
   }
   return resul;
 }