You are on page 1of 30

DBMS

Course Design Report

Design Topic Database Course Design


Mentor 兀坐晴窗独饮茶
Profession 陈建峡
Class 19lq
Student ID 1911521202
Name El Mazria Hajar
Date 2022/05/06
Catalog

1. Objective and significance of the project


2. System operation environment description
3. system requirements analysis
3.1. Organization chart
3.2. Data flow graph and data dictionary
3.3. System function structure
4. Database design
4.1 Conceptual design (E-R diagram)
4.2 Logical structure design
4.3 Physical structure design
5. Database implementation and operation
5.1 Introduction of database management system
5.2 Database creation and data entry
5.3 Database query
5.4 Database control
6. Program design description
6.1 Database connection
6.2 System menu
6.3 User login
6.4 Data entry, modification and deletion
6.5 Database query
7. Summary of course design
7.1 Problems and solutions in curriculum design
7.2 Analysis of existing problems
7.3 Experience of curriculum design
Database Course Design - Assignment
Management System
1. Title Description :

HUST Assignment Management System

Provides online communication between teachers and students.

Through the platform teachers can assign, collect, revise and count the

completion of assignments. Students can check their homework

corrections and communicate with their teachers at any time.

Asynchronous and synchronous communication modes are available, as

well as discussions on topical issues. Note: Assignments can be uploaded

and downloaded as attachments, and support for the usual mark statistics

etc.

1. Check the completion of each student's work by course number

2. Statistics of the usual marks for each course.

3. Query the completion of a particular assignment.


4. Query the content of a particular hot topic discussion.
2. System analysis

2.1 The main tasks to be completed in this topic are.

1. assigning the assignment (adding tuples to the Course table in the

database)

2. Collect the assignment (delete the tuples of the Course table in the

database)

3. Modify the assignment (modify the tuples in the Course table in the

database)

4. count the completion of assignments (join the Course, Student, and

Teacher tables to perform a query operation)

5. I chose to use the Java development language to connect to the mySQL

database because the topic requires the implementation of an application

platform
2.2 Explanation of the names in the ER diagram and in the

database

Before creating the database, use PowerDesigner to draw the ER diagram.

In this problem, Teacher represents a teacher, Student represents a

student, and Course represents a student taking a course from a teacher.

1. the Teacher table contains the attributes Tno (teacher number and is the

master code of the Teacher table), Tname (teacher name).

2. the Student table contains the attributes Sno (student number and is the

master code of the Student table), Sname (student name), Shomework

(completion of the assignment).

3. Course table contains the attributes Cno (course number), Cname

(course name), Cgrade (the usual grade of the course), Tno (teacher

number, for the Course table of the external code), Sno (student number,

for the Course of the external code) Cno, Tno, Sno together constitute the

main code of the Course

2.3 Table-to-Table Relationships

The Teacher table is connected to the Student table by the teach

relationship
The Teacher table is linked to the Course table by the assign relationship

The Student table is linked to the Course table by the study relationship

2.4 Design and Programming Environment

Programming environment: win10, mySQL, eclipse

Programming language: SQL language,


3. local ER diagram

Local ER diagram of Teacher and Student

Local ER diagram of Course and Student


Local ER diagram of Teacher and Course
The benefits of ER diagrams drawn using this approach are as follows :

First of all there are no redundant attributes in the ER diagram, every

non-primary attribute is completely dependent on the primary attribute.

And there are no passing dependencies, so this ER diagram is at least

third paradigm and therefore can greatly increase the efficiency of the

database. And the direct representation of each relationship is very clear,

and each table does describe the properties of the objects in the topic

clearly. Thus, the problem raised in the topic description is well solved
4. Overall ER diagram and pdm diagram generated from

ER diagram

Overall ER diagram
PDM diagram converted from ER diagram
Using this overall ER diagram with the advantage of no redundant

attributes when connecting and easy to export the database, the E-R

diagram is a powerful tool for abstracting and describing the display

world. The conceptual model represented by E-R diagrams is independent

of the data model supported by the specific DBMS, and it is a common

basis for various data models, thus more general, more abstract, and

closer to the real world than the data model.


5. SQL file generated from ER diagram
The mySQL command file exported from PowerDesigner's ER diagram

6. Create a database in mysql using the generated SQL file

The following commands are executed using the exported sql file pasted

into mysql
Command 1 : Create database

Command 2: If there is a table with the same name, drop all


Command 3: Create Course table

Command 4: Create Studet table


Command 5: Create Teacher table
7. Connecting to and manipulating databases using the Java

language
First you need the plugin named mysql-connector-java-8.0.11, create a lib

folder in the project, put this plugin in it and add the project path, after

that you can call many libraries. First use

Class.forName("com.mysql.cj.jdbc.Driver"); statement driver. Then

create a Connection object to connect to the database, and then write each

execution operation separately in a function, using the Statement's

executeQuery() method to query the database and the executeUpdate()

method to operate on the database

Add Student tuple


Add Student 2

Add Teacher
Add Course

Execute query operations


Delete Course

Delete Teacher

Delete Student

8. Java Code

package cn.farid;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

@SuppressWarnings("all")
public class Test {

public static void main(String[] args) throws Exception {


// 1.Load database driven;
Class.forName("com.mysql.cj.jdbc.Driver");

// 2.Connect database;
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/dbms_course?useSSL=false&serverTimezone=GMT%2B8",
"root", "123456");

// 3.Create Execute SQL;


Statement stmt = connection.createStatement();

// Execute SQL;
int cmd;
Scanner in = new Scanner(System.in);
while (true) {
System.out.println("Which operation to perform?\n 1.Search\t 2.ADD\t 3.Edit\t 4.Delete\t
5.Quit");
cmd = in.nextInt();
if (cmd == 1) {
Select(connection);
} else if (cmd == 2) {
Add(connection);
} else if (cmd == 3) {
Alter(connection);
} else if (cmd == 4) {
Delete(connection);
} else {
break;
}
}

// 6.Release resource;
stmt.close();
connection.close();
in.close();
}

// Search Function
public static void Select(Connection con) throws SQLException {
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(
"SELECT * FROM student,course,teacher WHERE teacher.Tno=course.Tno AND
course.Sno=student.Sno");
while (rs.next()) {
int sno = rs.getInt("student.Sno");
int tno = rs.getInt("teacher.Tno");
int cno = rs.getInt("course.Cno");
String sname = rs.getString("student.Sname");
String cname = rs.getString("course.Cname");
String tname = rs.getString("teacher.Tname");
double shomework = rs.getDouble("student.Shomework");
int cgrade = rs.getInt("course.Cgrade");
System.out.println("Name:" + sname + " 课程名:" + cname + " 老师:" + tname + " 分数:" +
cgrade + " 作业完成情况"
+ (shomework * 100) + "%");
}
}

// Add Function
public static void Add(Connection con) throws SQLException {
String Name[] = { "Student", "Teacher", "Course" };
System.out.println("Which tuple to add ?\n 1." + Name[0] + "\t2." + Name[1] + "\t3." +
Name[2] + "\t4.返回上一级");
Scanner sc = new Scanner(System.in);
int opt = sc.nextInt();
Statement st = con.createStatement();
int flag;
if (opt == 1) {
int sno;
String sname;
double shomework;
System.out.print("Sno:");
sno = sc.nextInt();
System.out.print("Sname:");
sname = sc.next();
System.out.print("Shomework:");
shomework = sc.nextDouble();
flag = st.executeUpdate("INSERT INTO `student`(Sno,Sname,Shomework) VALUES (" + sno +
",'" + sname + "',"
+ shomework + ")");
if (flag > 0) {
System.out.println("add Student success!");
}
} else if (opt == 2) {
int tno, cno;
String tname;
System.out.print("Tno:");
tno = sc.nextInt();
System.out.print("Tname:");
tname = sc.next();
flag = st.executeUpdate("INSERT INTO `teacher`(Tno,Tname) VALUES (" + tno + ",'" + tname
+ "')");
if (flag > 0) {
System.out.println("add Teacher success!");
}
} else if (opt == 3) {
int cno, cgrade, tno, sno;
String cname;
System.out.print("Cno:");
cno = sc.nextInt();
System.out.print("Cname:");
cname = sc.next();
System.out.print("Tno:");
tno = sc.nextInt();
System.out.print("Sno:");
sno = sc.nextInt();
System.out.print("Cgrade:");
cgrade = sc.nextInt();
flag = st.executeUpdate("INSERT INTO `course`(Cno,Cname,Cgrade,Tno,Sno) VALUES (" +
cno + ",'" + cname
+ "'," + cgrade + "," + tno + "," + sno + ")");
if (flag > 0) {
System.out.println("add Course success!");
}
}
}

// update Function
public static void Alter(Connection con) throws SQLException {
String Name[] = { "Student", "Teacher", "Course" };
System.out.println("Which tuple to edit? 1." + Name[0] + "\t2." + Name[1] + "\t3." +
Name[2] + "\t4.Back to previous level");
Scanner sc = new Scanner(System.in);
int opt = sc.nextInt();
Statement st = con.createStatement();
int flag;
if (opt == 1) {
int sno;
System.out.println("please input the Sno");
sno = sc.nextInt();
System.out.println("Which property to modify ?\n1.Sname\t 2.Shomework\t 3.Back to
previous level");
int index;
index = sc.nextInt();
System.out.println("Enter the modified value:");
if (index == 1) {
String sname;
sname = sc.next();
flag = st.executeUpdate("UPDATE student SET Sname=" + sname + " WHERE Sno=" +
sno);
if (flag > 0) {
System.out.println("Sno " + sno + "of Student of Sname edit success");
}
} else if (index == 2) {
double shomework;
shomework = sc.nextDouble();
flag = st.executeUpdate("UPDATE student SET Shomework=" + shomework + " WHERE
Sno=" + sno);
System.out.println("Sno : " + sno + " of Student 的 Shomework update success");
}
} else if (opt == 2) {
int tno;
System.out.println("please input the Tno");
tno = sc.nextInt();
System.out.println("Which property to modify?\n1.Tname\t 2.Back to previous level");
int index;
index = sc.nextInt();
System.out.println("Enter the modified value:");
if (index == 1) {
String tname;
tname = sc.next();
flag = st.executeUpdate("UPDATE teacher SET Tname=" + tname + " WHERE Tno=" +
tno);
if (flag > 0) {
System.out.println("Tno 为" + tno + "of Teacher of Tname update success");
}
}
} else if (opt == 3) {
int cno;
System.out.println("please input the Cno");
cno = sc.nextInt();
System.out.println("Which property to modify? \n1.Cname\t 2.Cgrade\t 3.Back to previous
level");
int index;
index = sc.nextInt();
System.out.println("Enter the modified value:");
if (index == 1) {
String cname;
cname = sc.next();
flag = st.executeUpdate("UPDATE course SET Cname=" + cname + " WHERE Cno=" +
cno);
if (flag > 0) {
System.out.println("Cno 为" + cno + "of course of Cname edit success!");
}
} else if (index == 2) {
int cgrade;
cgrade = sc.nextInt();
flag = st.executeUpdate("UPDATE course SET Cgrade=" + cgrade + " WHERE Cno=" +
cno);
System.out.println("Cno " + cno + "of course of Cgrade edit success");
}
}
}

// delete function
public static void Delete(Connection con) throws SQLException {
String Name[] = { "Student", "Teacher", "Course" };
System.out.println("Which tuple to delete ?\n1." + Name[0] + "\t2." + Name[1] + "\t3." +
Name[2] + "\t4.Back to previous level");
Scanner sc = new Scanner(System.in);
int opt = sc.nextInt();
Statement st = con.createStatement();
int flag;
if (opt == 1) {
int sno;
System.out.println("please input the Sno");
sno = sc.nextInt();
flag = st.executeUpdate("DELETE FROM student WHERE Sno=" + sno);
if (flag > 0) {
System.out.println("delete Student success ");
}
} else if (opt == 2) {
int tno;
System.out.println("please input the Tno");
tno = sc.nextInt();
flag = st.executeUpdate("DELETE FROM teacher WHERE Tno=" + tno);
if (flag > 0) {
System.out.println("delete Teacher success");
}
} else if (opt == 3) {
int cno;
System.out.println("please input the Cno");
cno = sc.nextInt();
flag = st.executeUpdate("DELETE FROM course WHERE Cno=" + cno);
if (flag > 0) {
System.out.println("delete Course success");
}
}
}
}

You might also like