数据库课程设计——MOOC学习平台
Posted z啵唧啵唧
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库课程设计——MOOC学习平台相关的知识,希望对你有一定的参考价值。
1. 项目介绍:
采用JDBC接口连接数据库,简单实现Mooc学习平台相关功能。
2.代码部分
1.方法类
package com.mooc;
import untlis.DButlis;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
public class Function_Mooc {
Scanner sc = new Scanner(System.in);
PreparedStatement ps = null;
ResultSet res = null;
DButlis tool = new DButlis();
//private static DButlis tool=null;
public Function_Mooc() {
}
//查看学校
public void See_School() {
//System.out.println("testnode2");
//1.建立链接
tool.getCon();
//System.out.println("testnode3");
//获取预编译的数据库操作对象
String sql = "select * from school";
ps = tool.createStatement(sql);
//处理查询结果集
try {
res = ps.executeQuery();
while (res.next()) {
int Scno = res.getInt(1);
String Scname = res.getString(2);
System.out.println(Scno + "," + Scname);
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close(res);
tool.close();
}
}
//添加学校
public int Add_School() {
String Scname=null;
System.out.println("请输入你要添加的学校名称");
Scname=sc.nextLine();
tool.getCon();
String sql = "insert into school (Scname) values(?)";
ps = tool.createStatement(sql);
try {
ps.setString(1,Scname);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close();
}
return 1;
}
//删除学校
public int Del_School() {
String Scname =null;
System.out.println("请输入你要删除的学校名称");
Scname=sc.nextLine();
tool.getCon();
String sql="delete from school where Scname=?";
ps = tool.createStatement(sql);
try {
ps.setString(1,Scname);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close();
}
return 1;
}
//查看课程分类
public void See_Cclass() {
tool.getCon();
String sql = "select Ccname from Cclass";
ps = tool.createStatement(sql);
try {
res = ps.executeQuery();
while (res.next()) {
String Ccname = res.getString(1);
System.out.println(Ccname);
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close(res);
tool.close();
}
}
//添加课程分类
public int Add_Cclass() {
String Ccname=null;
System.out.println("请输入你添加的课程分类");
Ccname = sc.nextLine();
tool.getCon();
String sql = "insert into cclass (Ccname) values(?)";
ps = tool.createStatement(sql);
try {
ps.setString(1,Ccname);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close();
}
return 1;
}
//删除课程分类
public int Del_Cclass() {
String Ccname =null;
System.out.println("请输入你删除的课程分类名");
Ccname = sc.nextLine();
tool.getCon();
String sql="delete from cclass where Ccname=?";
ps = tool.createStatement(sql);
try {
ps.setString(1,Ccname);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close();
}
return 1;
}
//查看教师信息
public void See_teacher() {
tool.getCon();
String sql = "select * from teacher";
ps = tool.createStatement(sql);
//处理查询结果集
try {
res = ps.executeQuery();
while (res.next()) {
int Tno = res.getInt(1);
String Tname = res.getString(2);
String Cno=res.getString(3);
int Kpno=res.getInt(4);
int Vidno=res.getInt(5);
System.out.println(Tno+","+Tname+","+Cno+","+Kpno+","+Vidno);
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close(res);
tool.close();
}
}
//添加教师
public int Add_teacher() {
//int Tno = 0;
String Tname =null;
String Cname=null;
int Kpno=0;
int Vidno=0;
tool.getCon();
System.out.println("请输入添加教师的姓名");
Tname = sc.nextLine();
System.out.println("请输入添加教师对应的课程名称");
Cname =sc.nextLine();
System.out.println("请输入添加教师对应的知识点编号");
Kpno =sc.nextInt();
System.out.println("请输入添加教师对应的视频编号");
Vidno =sc.nextInt();
String sql = "insert into teacher (Tname,Cname,Kpno,Vidno) values(?,?,?,?)";
ps = tool.createStatement(sql);
try {
//ps.setInt(1,Tno);
ps.setString(1,Tname);
ps.setString(2,Cname);
ps.setInt(3,Kpno);
ps.setInt(4,Vidno);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close();
}
return 1;
}
//删除教师
public int Del_teacher() {
String Tname =null;
System.out.println("请输入你要删除的老师的姓名");
Tname =sc.nextLine();
tool.getCon();
String sql="delete from teacher where Tname=?";
ps = tool.createStatement(sql);
try {
ps.setString(1,Tname);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close();
}
return 1;
}
//查看学生信息
public void See_student() {
tool.getCon();
String sql = "select * from student";
ps = tool.createStatement(sql);
//处理查询结果集
try {
res = ps.executeQuery();
while (res.next()) {
int Stuno=res.getInt(1);
String Stuname=res.getString(2);
String Cname = res.getString(3);
int Kpno = res.getInt(4);
System.out.println(Stuno+","+Stuname+","+Cname+","+Kpno);
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close(res);
tool.close();
}
}
//添加学生
public int Add_student() {
String Stuname =null;
String Cname = null;
int Kpno=0;
System.out.println("请输入添加的学生的姓名");
Stuname = sc.nextLine();
System.out.println("请输入添加学生所学课程");
Cname = sc.nextLine();
System.out.println("请输入课程对应知识点");
Kpno = sc.nextInt();
tool.getCon();
String sql = "insert into student (Stuname,Cname,Kpno) values(?,?,?)";
ps = tool.createStatement(sql);
try {
ps.setString(1,Stuname);
ps.setString(2,Cname);
ps.setInt(3,Kpno);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
tool.close(res);
tool.close();
}
return 1;
}
//删除学生
public int Del_student() {
String Stuname =null;
System.out.println("请输入你要删除的学生的姓名");
Stuname =sc.nextLine();
tool.getCon();
String sql="delete from student where Stuname=?";
ps = tool.createStatement(sql);
try {
ps.setString(1,Stuname);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
tool.close(res);
tool.close();
}
return 1;
}
//发布公告
public int Add_notice() {
String Notcno = null;
System.out.println("请输入你要发布的公告内容");
Notcno = sc.nextLine();
tool.getCon();
String sql="insert into notice (Notcno) values (?)";
ps=tool.createStatement(sql);
try {
ps.setString(1,Notcno);
ps.executeUpdate();
}catch (SQLException e)
{
e.printStackTrace();
}finally {
tool.close();
}
return 1;
}
//删除公告
public int Del_notice() {
int Notno = 0;
System.out.println("请输入你要删除的公告的编号");
Notno =sc.nextInt();
tool.getCon();
String sql="delete from notice where Notno=?";
ps = tool.createStatement(sql);
try {
ps.setInt(1,Notno);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
tool.close();
}
return 1;
}
//+------------------------以下是教师的相关方法------------------------+
//创建课程
public int Add_couse() {
tool.getCon();
String Cname=null;
int Kpno=0;
int Ccno=0;
System.out.println("请输入你要创建的课程的名字");
Cname = sc.nextLine();
System.out.println("请输入该课程对应的知识点编号");
Kpno = sc.nextInt();
System.out.println("请输入该课程对应的的课程分类编号");
Ccno = sc.nextInt();
String sql = "insert into couse (Cname,Kpno,Ccno) values (?,?,?)";
ps = tool.createStatement(sql);
try {
ps.setString(1,Cname);
ps.setInt(2,Kpno);
ps.setInt(3,Ccno);
ps.executeUpdate();
}catch (以上是关于数据库课程设计——MOOC学习平台的主要内容,如果未能解决你的问题,请参考以下文章
杨蓉庆201771010135《面向对象程序设计(java)》第一周学习总结
201771010108韩腊梅《面向对象程序设计(java)》第一周学习总结