ATIVIDADE:  BANCO DE DADOS
Autor: forleonardo | Publicado: 2011-05-05T08:37:00-07:00

Nesta atividade cada equipe de 3 a 4 alunos deverá realizar as tarefas listadas abaixo e em seguida enviar para o e-mail leonardo.santos@etep.edu.br a pasta com os arquivos zipados.

Lista de Tarefas:
Criar uma aplicação Web
Criar uma página denominada sessao.jsp &nbsp;que explica a diferença de escopo a nível de sessão e a nível de página
Criar uma página denominada controlador.jsp que explica as funções do controlador
Criar uma página denominada bean.jsp que explica
&nbsp;as funções de um bean&nbsp;
Como criar uma instância de um bean no controlador&nbsp;
Como criar uma instância de um bean em uma página jsp
Como acessar o valor de uma propriedade de um bean
Como modificar o valor de uma propriedade de um bean
Criar uma página denominada index.jsp que exibe todos os registros da tabela
Criar uma página denominada impar.jsp que exibe todos os registros da tabela de id ímpar
Criar uma página denominada par.jsp que exibe todos os registros da tabela de id par
Criar uma página denominada &nbsp;soment10.jsp que exibe somente os dez primeiros registros da tabela.
Criar uma página denominada insert.jsp que &nbsp;insere os dados de um novo registro a partir de um formulário
Criar uma página denominada lista.jsp com os links para todas &nbsp;outras páginas
**********
Base de dados: Use o código abaixo para criar a base de dados
**************

-- Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
--
-- You may not modify, use, reproduce, or distribute this software
-- except in compliance with the terms of the license at:
-- http://developer.sun.com/berkeley_license.html
--
-- author: tgiunipero
--

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

DROP SCHEMA IF EXISTS `affablebean` ;
CREATE SCHEMA IF NOT EXISTS `affablebean` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
USE `affablebean` ;

-- -----------------------------------------------------
-- Table `affablebean`.`customer`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `affablebean`.`customer` ;

CREATE &nbsp;TABLE IF NOT EXISTS `affablebean`.`customer` (
&nbsp; `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
&nbsp; `name` VARCHAR(45) NOT NULL ,
&nbsp; `email` VARCHAR(45) NOT NULL ,
&nbsp; `phone` VARCHAR(45) NOT NULL ,
&nbsp; `address` VARCHAR(45) NOT NULL ,
&nbsp; `city_region` VARCHAR(2) NOT NULL ,
&nbsp; `cc_number` VARCHAR(19) NOT NULL ,
&nbsp; PRIMARY KEY (`id`) )
ENGINE = InnoDB
COMMENT = 'maintains customer details';


-- -----------------------------------------------------
-- Table `affablebean`.`customer_order`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `affablebean`.`customer_order` ;

CREATE &nbsp;TABLE IF NOT EXISTS `affablebean`.`customer_order` (
&nbsp; `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
&nbsp; `amount` DECIMAL(6,2) NOT NULL ,
&nbsp; `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
&nbsp; `confirmation_number` INT UNSIGNED NOT NULL ,
&nbsp; `customer_id` INT UNSIGNED NOT NULL ,
&nbsp; PRIMARY KEY (`id`) ,
&nbsp; INDEX `fk_customer_order_customer` (`customer_id` ASC) ,
&nbsp; CONSTRAINT `fk_customer_order_customer`
&nbsp; &nbsp; FOREIGN KEY (`customer_id` )
&nbsp; &nbsp; REFERENCES `affablebean`.`customer` (`id` )
&nbsp; &nbsp; ON DELETE NO ACTION
&nbsp; &nbsp; ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'maintains customer order details';


-- -----------------------------------------------------
-- Table `affablebean`.`category`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `affablebean`.`category` ;

CREATE &nbsp;TABLE IF NOT EXISTS `affablebean`.`category` (
&nbsp; `id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT ,
&nbsp; `name` VARCHAR(45) NOT NULL ,
&nbsp; PRIMARY KEY (`id`) )
ENGINE = InnoDB
COMMENT = 'contains product categories, e.g., dairy, meats, etc.';


-- -----------------------------------------------------
-- Table `affablebean`.`product`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `affablebean`.`product` ;

CREATE &nbsp;TABLE IF NOT EXISTS `affablebean`.`product` (
&nbsp; `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
&nbsp; `name` VARCHAR(45) NOT NULL ,
&nbsp; `price` DECIMAL(5,2) NOT NULL ,

&nbsp; -- Delete after description is moved to resource bundle
&nbsp; `description` TINYTEXT NULL ,

&nbsp; `last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
&nbsp; `category_id` TINYINT UNSIGNED NOT NULL ,
&nbsp; PRIMARY KEY (`id`) ,
&nbsp; INDEX `fk_product_category` (`category_id` ASC) ,
&nbsp; CONSTRAINT `fk_product_category`
&nbsp; &nbsp; FOREIGN KEY (`category_id` )
&nbsp; &nbsp; REFERENCES `affablebean`.`category` (`id` )
&nbsp; &nbsp; ON DELETE NO ACTION
&nbsp; &nbsp; ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'contains product details';


-- -----------------------------------------------------
-- Table `affablebean`.`ordered_product`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `affablebean`.`ordered_product` ;

CREATE &nbsp;TABLE IF NOT EXISTS `affablebean`.`ordered_product` (
&nbsp; `customer_order_id` INT UNSIGNED NOT NULL ,
&nbsp; `product_id` INT UNSIGNED NOT NULL ,
&nbsp; `quantity` SMALLINT UNSIGNED NOT NULL DEFAULT 1 ,
&nbsp; PRIMARY KEY (`customer_order_id`, `product_id`) ,
&nbsp; INDEX `fk_ordered_product_customer_order` (`customer_order_id` ASC) ,
&nbsp; INDEX `fk_ordered_product_product` (`product_id` ASC) ,
&nbsp; CONSTRAINT `fk_ordered_product_customer_order`
&nbsp; &nbsp; FOREIGN KEY (`customer_order_id` )
&nbsp; &nbsp; REFERENCES `affablebean`.`customer_order` (`id` )
&nbsp; &nbsp; ON DELETE NO ACTION
&nbsp; &nbsp; ON UPDATE NO ACTION,
&nbsp; CONSTRAINT `fk_ordered_product_product`
&nbsp; &nbsp; FOREIGN KEY (`product_id` )
&nbsp; &nbsp; REFERENCES `affablebean`.`product` (`id` )
&nbsp; &nbsp; ON DELETE NO ACTION
&nbsp; &nbsp; ON UPDATE NO ACTION)
ENGINE = InnoDB
COMMENT = 'matches products with customer orders and records their quantity';



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;


*************
Use o código abaixo para&nbsp;inserção de dados

*****************


USE affablebean;
INSERT INTO `category` (name) VALUES ('dairy'),('meats'),('bakery'),('fruit &amp; veg');

USE affablebean;

INSERT INTO `product` (`name`, price, description, category_id) VALUES ('milk', 1.70, 'semi skimmed (1L)', 1);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('cheese', 2.39, 'mild cheddar (330g)', 1);

INSERT INTO `product` (`name`, price, description, category_id) VALUES ('butter', 1.09, 'unsalted (250g)', 1);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('free range eggs', 1.76, 'medium-sized (6 eggs)', 1);

INSERT INTO `product` (`name`, price, description, category_id) VALUES ('organic meat patties', 2.29, 'rolled in fresh herbs&lt;br&gt;2 patties (250g)', 2);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('parma ham', 3.49, 'matured, organic (70g)', 2);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('chicken leg', 2.59, 'free range (250g)', 2);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('sausages', 3.55, 'reduced fat, pork&lt;br&gt;3 sausages (350g)', 2);

INSERT INTO `product` (`name`, price, description, category_id) VALUES ('sunflower seed loaf', 1.89, '600g', 3);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('sesame seed bagel', 1.19, '4 bagels', 3);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('pumpkin seed bun', 1.15, '4 buns', 3);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('chocolate cookies', 2.39, 'contain peanuts&lt;br&gt;(3 cookies)', 3);

INSERT INTO `product` (`name`, price, description, category_id) VALUES ('corn on the cob', 1.59, '2 pieces', 4);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('red currants', 2.49, '150g', 4);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('broccoli', 1.29, '500g', 4);
INSERT INTO `product` (`name`, price, description, category_id) VALUES ('seedless watermelon', 1.49, '250g', 4);


--INSERT INTO `product` (`name`, price, category_id) VALUES ('milk', 1.70, 1);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('cheese', 2.39, 1);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('butter', 1.09, 1);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('free range eggs', 1.76, 1);
--
--INSERT INTO `product` (`name`, price, category_id) VALUES ('organic meat patties', 2.29, 2);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('parma ham', 3.49, 2);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('chicken leg', 2.59, 2);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('sausages', 3.55, 2);
--
--INSERT INTO `product` (`name`, price, category_id) VALUES ('sunflower seed loaf', 1.89, 3);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('sesame seed bagel', 1.19, 3);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('pumpkin seed bunbun', 1.15, 3);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('chocolate cookies', 2.39, 3);
--
--INSERT INTO `product` (`name`, price, category_id) VALUES ('corn on the cob', 1.59, 4);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('red currants', 2.49, 4);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('broccoli', 1.29, 4);
--INSERT INTO `product` (`name`, price, category_id) VALUES ('seedless watermelon', 1.49, 4);


--
-- Sample data for table `customer`
--

USE affablebean;
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Charlie Pace', 'c.pace@youareeverybody.com', '605434778', 'Å irokÃ¡ 45', '1', '4224311324421331');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('MC Hammer', 'hammer@hammertime.com', '226884562', 'RuskÃ¡ 11', '2', '4321123443211234');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Karel Gott', 'gott@karelgott.com', '224517995', 'KostelnÃ­ 83', '7', '3311332222444411');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Helena VondrÃ¡ÄkovÃ¡', 'h.vondrackova@seznam.cz', '224517995', 'LetohradskÃ¡ 18', '7', '1111222244443333');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Sawyer Ford', 'sawyer.ford@gmail.com', '204888845', 'DuÅ¡nÃ­ 87', '1', '2222333311114444');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Dalibor Janda', 'dalibor@dalibor.cz', '728331184', 'KrkonoÅ¡skÃ¡ 9', '3', '3111444222212334');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Richard Genzer', 'r.genzer@nova.cz', '737610775', 'PlzeÅˆskÃ¡ 131', '5', '2244443321123311');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Iveta BartoÅ¡ovÃ¡', 'i.bartosova@volny.cz', '734556133', 'ProkopskÃ¡ 60', '1', '3333111144442222');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Jin-Soo Kwon', 'jin.kwon@hotmail.kr', '606338909', 'Ve StÅ™eÅ¡oviÄkÃ¡ch 49', '6', '1111222233334444');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Benjamin Linus', 'b.linus@lost.com', '222756448', 'DruÅ¾stevnÃ­ 77', '4', '4444222233331111');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('LeoÅ¡ MareÅ¡', 'mares@ferrari.it', '608995383', 'PaÅ™Ã­Å¾skÃ¡ 89', '1', '2222444411113333');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('John Locke', 'maninblack@lostpedia.com', '413443727', 'ValeÄovskÃ¡ 20', '9', '2244331133114422');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Lucie BÃ­lÃ¡', 'lucie@jampadampa.cz', '733556813', 'Na hÃ¡jku 3', '8', '3333444422221111');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Sayid Jarrah', 'sayid@gmail.com', '602680793', 'KodaÅˆskÃ¡ 78', '10', '5490123456789128');
INSERT INTO `customer` (`name`, email, phone, address, city_region, cc_number) VALUES ('Hugo Reyes', 'hurley@mrcluck.com', '605449336', 'Å½erotÃ­nova 64', '3', '4539992043491562');