1. 程式人生 > >Java EE 7 Hands-on Lab,MySQL版

Java EE 7 Hands-on Lab,MySQL版

[list]
[*]配置GlassFish的MySQL連線池並在persistence.xml中啟用<jta-data-source>且設定好JNDI。
[*]修改sql檔案。
[*]重啟專案。
[*]關於本文提到的示例程式碼[url]http://download.csdn.net/detail/runandrun/8429367[/url]可下載,或者看[url]http://tryrefine.iteye.com/blog/2183634[/url]
[*]歡迎點選後面的連結加入群【JavaEE GlassFish NetBeans OSGI】(187515899)一起學習討論:[url]http://jq.qq.com/?_wv=1027&k=ZCvkA9[/url]
[/list]

[b]create.sql[/b]

CREATE TABLE IF NOT EXISTS THEATER (ID INTEGER not null primary key, CAPACITY INTEGER not null)
CREATE TABLE IF NOT EXISTS MOVIE(ID INTEGER not null primary key, NAME VARCHAR(50) not null, ACTORS VARCHAR(200) not null)
CREATE TABLE IF NOT EXISTS TIMESLOT(ID INTEGER not null primary key, START_TIME VARCHAR(5) not null, END_TIME VARCHAR(5) not null)
CREATE TABLE IF NOT EXISTS SHOW_TIMING(ID INTEGER not null primary key, DAY INTEGER not null, THEATER_ID INTEGER not null, MOVIE_ID INTEGER not null, TIMING_ID INTEGER not null)
CREATE TABLE IF NOT EXISTS SALES(ID INTEGER not null primary key, AMOUNT FLOAT not null)
CREATE TABLE IF NOT EXISTS POINTS(ID INTEGER not null primary key, POINTS INTEGER not null)
ALTER TABLE SHOW_TIMING ADD CONSTRAINT SHOW_THEATER_FK FOREIGN KEY (THEATER_ID) REFERENCES THEATER (ID)
ALTER TABLE SHOW_TIMING ADD CONSTRAINT SHOW_MOVIE_FK FOREIGN KEY (MOVIE_ID) REFERENCES MOVIE (ID)
ALTER TABLE SHOW_TIMING ADD CONSTRAINT TIMESLOT_FK FOREIGN KEY (TIMING_ID) REFERENCES TIMESLOT (ID)
ALTER TABLE SALES ADD CONSTRAINT SHOW_TIMING_ID_FK FOREIGN KEY (ID) REFERENCES SHOW_TIMING (ID)


[b]drop.sql[/b]

DROP TABLE IF EXISTS SALES;
DROP TABLE IF EXISTS POINTS;
DROP TABLE IF EXISTS SHOW_TIMING;
DROP TABLE IF EXISTS MOVIE;
DROP TABLE IF EXISTS TIMESLOT;
DROP TABLE IF EXISTS THEATER;


[b]load.sql[/b]

INSERT INTO THEATER(ID, CAPACITY) VALUES (1, 50) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO THEATER(ID, CAPACITY) VALUES (2, 70) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO THEATER(ID, CAPACITY) VALUES (3, 70) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO THEATER(ID, CAPACITY) VALUES (4, 60) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO THEATER(ID, CAPACITY) VALUES (5, 120) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO THEATER(ID, CAPACITY) VALUES (6, 100) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO THEATER(ID, CAPACITY) VALUES (7, 80) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (1, 'The Matrix', 'Keanu Reeves, Laurence Fishburne, Carrie-Ann Moss') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (2, 'The Lord of The Rings', 'Elijah Wood, Ian Mckellen, Viggo Mortensen') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (3, 'Inception', 'Leonardo DiCaprio') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (4, 'The Shining', 'Jack Nicholson, Shelley Duvall') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (5, 'Mission Impossible', 'Tom Cruise, Jeremy Renner') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (6, 'Terminator', 'Arnold Schwarzenegger, Linda Hamilton') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (7, 'Titanic', 'Leonardo DiCaprio, Kate Winslet') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (8, 'Iron Man', 'Robert Downey Jr, Gwyneth Paltrow, Terrence Howard') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (9, 'Inglorious Bastards', 'Brad Pitt, Diane Kruger') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (10, 'Million Dollar Baby', 'Hillary Swank, Client Eastwood') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (11, 'Kill Bill', 'Uma Thurman') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (12, 'The Hunger Games', 'Jennifer Lawrence') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (13, 'The Hangover', 'Bradley Cooper, Zach Galifianakis') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (14, 'Toy Story', 'Tom Hanks, Michael Keaton') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (15, 'Harry Potter', 'Daniel Radcliffe, Emma Watson') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (16, 'Avatar', 'Sam Worthington, Sigourney Weaver') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (17, 'Slumdog Millionaire', 'Anil Kapoor, Dev Patel, Freida Pinto') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (18, 'The Curious Case of Benjamin Button', 'Brad Pitt, Cate Blanchett') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (19, 'The Bourne Ultimatum', 'Matt Damon, Julia Stiles') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO MOVIE(ID, NAME, ACTORS) VALUES (20, 'The Pink Panther', 'Steve Martin, Kevin Kline') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO TIMESLOT(ID, START_TIME, END_TIME) VALUES (1, '10:00', '11:45') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO TIMESLOT(ID, START_TIME, END_TIME) VALUES (2, '12:00', '01:45') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO TIMESLOT(ID, START_TIME, END_TIME) VALUES (3, '02:00', '03:45') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO TIMESLOT(ID, START_TIME, END_TIME) VALUES (4, '04:00', '05:45') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO TIMESLOT(ID, START_TIME, END_TIME) VALUES (5, '06:00', '07:45') ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (1, 1, 1, 1, 1) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (2, 1, 1, 2, 2) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (3, 1, 1, 3, 3) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (4, 1, 1, 4, 4) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (5, 1, 1, 5, 5) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (6, 1, 2, 6, 1) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (7, 1, 2, 7, 2) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (8, 1, 2, 8, 3) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (9, 1, 2, 9, 4) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (10, 1, 2, 10, 5) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (11, 1, 3, 11, 1) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (12, 1, 3, 12, 2) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (13, 1, 3, 13, 3) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (14, 1, 3, 14, 4) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (15, 1, 3, 15, 5) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (16, 1, 4, 16, 1) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (17, 1, 4, 17, 2) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (18, 1, 4, 18, 3) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (19, 1, 4, 19, 4) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (20, 1, 4, 20, 5) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (21, 1, 5, 1, 1) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (22, 1, 5, 2, 2) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (23, 1, 5, 3, 3) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (24, 1, 5, 4, 4) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (25, 1, 5, 5, 5) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (26, 1, 6, 6, 1) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (27, 1, 6, 7, 2) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (28, 1, 6, 8, 3) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (29, 1, 6, 9, 4) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (30, 1, 6, 10, 5) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (31, 1, 7, 11, 1) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (32, 1, 7, 12, 2) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (33, 1, 7, 13, 3) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (34, 1, 7, 14, 4) ON DUPLICATE KEY UPDATE ID=ID;
INSERT INTO SHOW_TIMING(ID, DAY, THEATER_ID, MOVIE_ID, TIMING_ID) VALUES (35, 1, 7, 15, 5) ON DUPLICATE KEY UPDATE ID=ID;