0% found this document useful (0 votes)
9 views

Test1 GivenToStudent

this is document

Uploaded by

nguyen05082004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Test1 GivenToStudent

this is document

Uploaded by

nguyen05082004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Bài 1: Cho Database

USE [Trading2021]
GO
/****** Object: Table [dbo].[Department] Script Date: 3/2/2020 4:57:51 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Department](
[id] [int] NOT NULL,
[name] [varchar](150) NOT NULL,
CONSTRAINT [PK_Department] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Employee] Script Date: 3/2/2020 4:57:51 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Employee](
[id] [int] NOT NULL,
[name] [varchar](150) NOT NULL,
[dob] [date] NOT NULL,
[gender] [bit] NOT NULL,
[did] [int] NOT NULL,
CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
INSERT [dbo].[Department] ([id], [name]) VALUES (1, N'IS')
INSERT [dbo].[Department] ([id], [name]) VALUES (2, N'IA')
INSERT [dbo].[Employee] ([id], [name], [dob], [gender], [did]) VALUES (1, N'mr A',
CAST(N'2000-01-01' AS Date), 1, 2)
INSERT [dbo].[Employee] ([id], [name], [dob], [gender], [did]) VALUES (2, N'mr AA',
CAST(N'2000-01-01' AS Date), 1, 1)
INSERT [dbo].[Employee] ([id], [name], [dob], [gender], [did]) VALUES (3, N'mr B',
CAST(N'2000-01-01' AS Date), 1, 1)
INSERT [dbo].[Employee] ([id], [name], [dob], [gender], [did]) VALUES (4, N'mr BBB',
CAST(N'2000-01-01' AS Date), 1, 2)
ALTER TABLE [dbo].[Employee] WITH CHECK ADD CONSTRAINT [FK_ Employee_Department]
FOREIGN KEY([did])
REFERENCES [dbo].[Department] ([id])
GO
Employee
Department
Id
Id Name
name Dob

Gender

did

/search

Bước 1:
Department.java (id,name)
Employee.java(id,name,dob,gender,depts)
Bước 2:
- DepartmentDAO.java:
List<Department> getAllDepts();
select * from department
- EmployeeDAO.java
- select e.id,e.name,e.gender,e.dob,e.did,d.name
from Employee e inner join Department d on (d.id=e.did)
where 1=1
Bước 3:
Tạo /search
Viết vào doGet:
DepartmentDAO deptDB = new DepartmentDAO();
List<Department> depts = deptDB.getAllDepts();
request.setAttribute("depts", depts);
EmployeeDAO edb=new EmployeeDAO();
List<Employee> emps=edb.searchEmps(null,null, 0);
request.setAttribute("emps", emps);
request.getRequestDispatcher("list.jsp").forward(request, response);
Bước 4: list.jsp:
Bước 5: viết vào doPost (/search):

Bài 2: Cho Database

You might also like