文章目录
- 1. 项目介绍:
- 2.代码部分
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 (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//编辑课程详情页面public void Edit_couse() {System.out.println("编辑课程详情页面");}
//删除课程public int Del_couse() {tool.getCon();String Cname = null;System.out.println("请输入你要删除课程的名称");Cname = sc.nextLine();String sql = "delete from couse where Cname=?";ps = tool.createStatement(sql);try {ps.setString(1,Cname);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//创建知识点public int Add_Knopoints() {tool.getCon();String Kpname = null;System.out.println("请输入你要添加的知识点的名称");Kpname = sc.nextLine();String sql = "insert into Knopoints (Kpname) values (?)";ps=tool.createStatement(sql);try {ps.setString(1,Kpname);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//辑知识点详情页面public void Edit_Knopoints(){System.out.println("编辑知识点详情页面");}
//删除知识点public int Del_Knopoints() {tool.getCon();String Kpname = null;System.out.println("请输入你要删除的知识点名称");Kpname = sc.nextLine();String sql = "delete from Knopoints where Kpname=?";ps = tool.createStatement(sql);try {ps.setString(1,Kpname);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//上传视频public int Add_video() {tool.getCon();String Vidname = null;String Vidpath = null;System.out.println("请输入你要添加的视频的名称");Vidname = sc.nextLine();System.out.println("请输入该视频的路径");Vidpath = sc.nextLine();String sql = "insert into video (Vidname,Vidpath) values (?,?)";ps=tool.createStatement(sql);try {ps.setString(1,Vidname);ps.setString(2,Vidpath);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//更新视频,update 表名 set 字段名1=值1,字段名2=值2... where 条件;public int Update_video() {tool.getCon();String Vidname1 = null;String Vidname2 = null;String Vidpath = null;System.out.println("请输入你要更新的视频的名称");Vidname1 = sc.nextLine();System.out.println("请输入更新后的视频的名字");Vidname2 = sc.nextLine();System.out.println("请输入更新后的视频路径");Vidpath = sc.nextLine();String sql = "update video set Vidname=?,Vidpath=? where Vidname=?";ps=tool.createStatement(sql);try {ps.setString(1,Vidname2);ps.setString(2,Vidpath);ps.setString(3,Vidname1);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}return 1;}
//删除视频public int Del_video() {tool.getCon();String Vidname = null;System.out.println("请输入你要删除的视频名称");Vidname = sc.nextLine();String sql = "delete from video where Vidname=?";ps = tool.createStatement(sql);try {ps.setString(1,Vidname);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//查看留言public void See_point() {tool.getCon();String Stucom = null;String sql = "select Stucom from comment ";ps = tool.createStatement(sql);try{System.out.println("学生的留言如下:");res = ps.executeQuery();while (res.next()){Stucom = res.getString(1);System.out.println(Stucom);}}catch (SQLException e){e.printStackTrace();}finally {tool.close();tool.close(res);}}
//回复留言
public int Reply_point() {See_point();String Teacom = null;String Stucom = null;System.out.println("请问你想在哪条留言后回复");Stucom = sc.nextLine();System.out.println("请问你的回复内容是");Teacom = sc.nextLine();String sql = "update comment set Teacom = ? where Stucom = ?";ps=tool.createStatement(sql);try {ps.setString(1,Teacom);ps.setString(2,Stucom);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;
}
//上传课后题public int Add_subject() {tool.getCon();String Subname = null;String Subans1 = null;String Subans2 = null;int Kpno = 0;System.out.println("请输入你要添加的题目");Subname = sc.nextLine();System.out.println("请输入全部选项");Subans1 = sc.nextLine();System.out.println("请输入正确选项");Subans2 = sc.nextLine();System.out.println("请输入该知识点对应的知识点编号");Kpno = sc.nextInt();String sql = "insert into subject (Subname,Subans1,Subans2,Kpno) values (?,?,?,?)";ps=tool.createStatement(sql);try {ps.setString(1,Subname);ps.setString(2,Subans1);ps.setString(3,Subans2);ps.setInt(4,Kpno);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//删除课后题public int Del_subject() {tool.getCon();int Subno = 0;System.out.println("请输入你要删除的题目的编号");Subno = sc.nextInt();String sql = "delete from subject where Subno=?";ps = tool.createStatement(sql);try {ps.setInt(1,Subno);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;
}//+------------------------以下是学生的相关方法------------------------+
//浏览课程public void See_couse() {tool.getCon();String sql = "select * from couse";ps = tool.createStatement(sql);try {res = ps.executeQuery();while (res.next()) {int Cno = res.getInt(1);String Cname = res.getString(2);int Kpno = res.getInt(3);int Ccno = res.getInt(4);System.out.println(Cno + "," + Cname+","+Kpno+","+Ccno);}} catch (SQLException e) {e.printStackTrace();}finally {tool.close(res);tool.close();}}
//收藏课程public int Add_colcouse() {tool.getCon();String Colname = null;System.out.println("请输入你要收藏的课程名称");Colname = sc.nextLine();String sql = "insert into colcouse (Colname) values (?)";ps=tool.createStatement(sql);try {ps.setString(1,Colname);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//学习课程public int Add_stucouse() {tool.getCon();String Stucname = null;System.out.println("请输入你要学习的课程名称");Stucname = sc.nextLine();String sql = "insert into stucouse (Stucname) values (?)";ps=tool.createStatement(sql);try {ps.setString(1,Stucname);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//评价课程public int Add_evaluate() {tool.getCon();String Cname = null;String Evaluate= null;System.out.println("请输入你要评价的课程名称");Cname = sc.nextLine();System.out.println("请输入你对该课程的评价");Evaluate = sc.nextLine();String sql = "insert into evaluate (Evaluate,Cname) values (?,?)";ps=tool.createStatement(sql);try {ps.setString(1,Evaluate);ps.setString(2,Cname);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//在线答题public void Online_answer() {System.out.println("准备好开始答题哦,本次作答共5道选择题每题5分,作答时间不限!");tool.getCon();int Kpno = 0;int tag = 1;int count = 0;int testnode1 = 1;String daan = null;// String daan = null;System.out.println("请问你想答那个知识点的题目?");Kpno = sc.nextInt();String sql = "select Subno,Subname,Subans1,Subans2,Kpno from subject where Kpno = ?";ps = tool.createStatement(sql);try {ps.setInt(1,Kpno);//ps.executeUpdate();res=ps.executeQuery();while (res.next()){String Subname = res.getString(2);String Subans1 = res.getString(3);String Subans2 = res.getString(4);System.out.println("第"+tag+"题: "+Subname);System.out.println(Subans1);System.out.println("请输入你的答案");if(testnode1 == 1){String daan1 = sc.nextLine();testnode1++;}daan = sc.nextLine();if(daan.equals(Subans2)){System.out.println("恭喜你答对了^_^");count++;}else{System.out.println("小笨蛋你答错了T_T");}tag++;}int score=count*5;System.out.println("你最终的得分是:"+score);}catch (SQLException e){e.printStackTrace();}finally {tool.close();tool.close(res);}}
//发表评论
public int Add_comment() {tool.getCon();String Stucom = null;String Stucom1 = null;int Kpno = 0;System.out.println("请问你想在哪一个知识点后面留言?");Kpno = sc.nextInt();System.out.println("请输入你要发表的评论");Stucom1 = sc.nextLine();Stucom = sc.nextLine();String sql = "insert into comment (Stucom,Kpno) values (?,?) ";ps=tool.createStatement(sql);try {ps.setString(1,Stucom);ps.setInt(2,Kpno);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}//注册用户
public int zhuce()
{tool.getCon();String username = null;int usepwd = 0;int key = 0;System.out.println("|-------注册要求如下--------------------|");System.out.println("|-------1.管理员注册用户名以adm开头------|");System.out.println("|-------2.教师注册用户名以tea开头--------|");System.out.println("|-------3.学生注册用户名以stu开头--------|");System.out.println("|-------4.密码为统一为纯数字-------------|");System.out.println("请输入你要注册的用户名:");username = sc.nextLine();System.out.println("请输入你要注册的用户密码");usepwd = sc.nextInt();System.out.println("请输入你的关键字");System.out.println("******提示******");System.out.println("|-------管理员关键字:1--------------|");System.out.println("|-------教师关键字: 2--------------|");System.out.println("|-------学生关键字: 3--------------|");key = sc.nextInt();String sql = "insert into user (username,userpwd,key1) values (?,?,?) ";//ps=tool.createStatement(sql);try {ps.setString(1,username);ps.setInt(2,usepwd);ps.setInt(3,key);ps.executeUpdate();}catch (SQLException e){e.printStackTrace();}finally {tool.close();}return 1;}
//访问视图
public void See_Z_GL() {//1.建立链接tool.getCon();//获取预编译的数据库操作对象String sql = "select * from z_gl; ";ps = tool.createStatement(sql);//处理查询结果集try {res = ps.executeQuery();while (res.next()) {String Scname = res.getString(1);String Tname = res.getString(2);String Cname = res.getString(3);System.out.println(Scname+ "," + Tname+","+Cname);}} catch (SQLException e) {e.printStackTrace();}finally {tool.close(res);tool.close();}
}
}
2.管理员类
package com.mooc;
/*
* 管理员类
* Alt+ins 快捷生成各种方法
* */
import java.util.Scanner;
public class Manager {Show show = new Show();Function_Mooc function_mooc = new Function_Mooc();public Manager() {}public void show_manger(){show.show2();Scanner sc =new Scanner(System.in);int flag=0;while(true){System.out.println("请输入你的选择");flag=sc.nextInt();switch (flag){case 1:function_mooc.See_School();break;case 2:int tag1=function_mooc.Add_School();if(tag1==1){System.out.println("该学校添加成功!");}break;case 3:int tag2=function_mooc.Del_School();if(tag2==1){System.out.println("该学校删除成功!");}break;case 4:function_mooc.See_Cclass();break;case 5:int tag3=function_mooc.Add_Cclass();if(tag3==1){System.out.println("课程分类添加成功!");}break;case 6:int tag4=function_mooc.Del_Cclass();if(tag4==1){System.out.println("课程分类删除成功!");}break;case 7:function_mooc.See_teacher();break;case 8:int tag5=function_mooc.Add_teacher();if (tag5 ==1){System.out.println("教师信息添加成功!");}break;case 9:int tag6=function_mooc.Del_teacher();if (tag6==1){System.out.println("该老师删除成功!");}break;case 10:function_mooc.See_student();break;case 11:int tag7 = function_mooc.Add_student();if(tag7==1){System.out.println("学生信息添加成功!");}break;case 12:int tag8=function_mooc.Del_student();if(tag8==1){System.out.println("该学生信息删除成功!");}break;case 13:int tag9=function_mooc.Add_notice();if(tag9==1){System.out.println("公告添加成功!");}break;case 14:int tag10=function_mooc.Del_notice();if(tag10==1){System.out.println("公告删除成功");}int x =sc.nextInt();break;case 15:function_mooc.See_Z_GL();break;case 16:System.out.println("感谢您的使用,再见!");System.exit(0);//JVM退出}}}
}
3.学生类
package com.mooc;
import java.security.spec.RSAOtherPrimeInfo;
import java.util.Scanner;
public class Student {Show show = new Show();Function_Mooc function_mooc = new Function_Mooc();Scanner sc = new Scanner(System.in);public Student() {}public void show_student() {show.show4();Scanner sc = new Scanner(System.in);int flag = 0;while (true) {System.out.println("请输入你的选择");flag = sc.nextInt();switch (flag) {case 1:function_mooc.See_couse();break;case 2:int tag1=function_mooc.Add_colcouse();if(tag1==1){System.out.println("该课程收藏成功!");}break;case 3:int tag3 = function_mooc.Add_stucouse();if (tag3 == 1) {System.out.println("已将该课程添加到学习列表!");}break;case 4:int tag4 = function_mooc.Add_evaluate();if (tag4 == 1) {System.out.println("评价成功!");}break;case 5:function_mooc.Online_answer();break;case 6:int tag5 = function_mooc.Add_comment();if(tag5 == 1){System.out.println("评论成功!");}break;case 7:System.out.println("感谢您的使用,再见!");System.exit(0);//JVM退出}}}
}
4.教师类
package com.mooc;
import java.util.Scanner;
public class Teacher {Show show = new Show();Function_Mooc function_mooc = new Function_Mooc();Scanner sc = new Scanner(System.in);public Teacher() {}public void show_teacher(){show.show3();Scanner sc =new Scanner(System.in);int flag=0;while(true){System.out.println("请输入你的选择");flag=sc.nextInt();switch (flag){case 1:int tag1=function_mooc.Add_couse();if(tag1==1){System.out.println("课程创建成功!");}break;case 2:function_mooc.Edit_couse();break;case 3:int tag2=function_mooc.Del_couse();if(tag2==1){System.out.println("该课程删除成功!");}break;case 4:int tag3=function_mooc.Add_Knopoints();if(tag3==1){System.out.println("该知识点添加成功!");}break;case 5:function_mooc.Edit_Knopoints();break;case 6:int tag4=function_mooc.Del_Knopoints();if(tag4==1){System.out.println("知识点删除成功!");}break;case 7:int tag5=function_mooc.Add_video();if(tag5==1){System.out.println("该视频上传成功!");}break;case 8:int tag6=function_mooc.Update_video();if(tag6 == 1){System.out.println("视频更新成功!");}break;case 9:int tag7=function_mooc.Del_video();if(tag7==1){System.out.println("该视频删除成功!");}break;case 10:int tag10 = function_mooc.Reply_point();if(tag10 == 1){System.out.println("回复成功!");}break;case 11:int tag8=function_mooc.Add_subject();if(tag8==1){System.out.println("该题目上传成功!");}break;case 12:int tag9=function_mooc.Del_subject();if(tag9==1){System.out.println("题目删除成功!");}break;case 13:System.out.println("感谢您的使用,再见!");System.exit(0);//JVM退出}}}
}
5.账户登陆
package com.mooc;
import untlis.DButlis;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Test {Runtime runtime = Runtime.getRuntime();Scanner sc = new Scanner(System.in);DButlis tool=new DButlis();Manager manager = new Manager();Student student = new Student();Teacher teacher = new Teacher();public Test() {}public int Login(Map<String, String> userLongInfor){//我在这儿打个标记int loginsucss = 0;PreparedStatement ps = null;ResultSet res=null;String username= userLongInfor.get("loginName");String password= userLongInfor.get("loginPwd");tool.getCon();String sql = "select key1 from user where username=? and userpwd=?";ps=tool.createStatement(sql);try {ps.setString(1,username);ps.setString(2,password);res=ps.executeQuery();/*if (res.next()){*/while (res.next()){if(res.getInt(1)==1){loginsucss=1;}else if(res.getInt(1)==2){loginsucss=2;}else if(res.getInt(1)==3){loginsucss=3;}}/*}*//*else{loginsucss=4;}*/} catch (SQLException e) {e.printStackTrace();}tool.close();tool.close(res);return loginsucss;}public Map<String, String> Init_Ui() {System.out.println("请输入你的账户");Scanner sc = new Scanner(System.in);System.out.println("用户名:");String loginName = sc.nextLine();System.out.println("密码:");String loginPwd = sc.nextLine();Map<String, String> userLongInfor = new HashMap<>();userLongInfor.put("loginName", loginName);userLongInfor.put("loginPwd", loginPwd);return userLongInfor;}public void denglu() {//int flag = 0;Map<String, String> userinfor = Init_Ui();int flag=Login(userinfor);boolean quit2 = false;while (!quit2){/*Map<String, String> userinfor = Init_Ui();int flag=Login(userinfor);System.out.println("test"+flag);*/switch (flag){case 1:manager.show_manger();break;case 2:teacher.show_teacher();break;case 3:student.show_student();break;/* case 4:System.out.println("账户名或密码输入有误,请重新输入!");break;*/}}}
}
6.JDBC工具类
package untlis;
import java.sql.*;
public class DButlis {final String URL="jdbc:mysql://localhost:3306/mooc_study";final String USERNAME="root";final String PASSWORD="15241";PreparedStatement ps= null;Connection con = null;//将jar包中driver实现类加载到JVM中static{try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException e) {e.printStackTrace();}}//封装连接通道创建细节public Connection getCon(){try {con= DriverManager.getConnection(URL, USERNAME, PASSWORD);} catch (SQLException e) {e.printStackTrace();}return con;}//封装交通工具创建细节public PreparedStatement createStatement(String sql){try {ps = getCon().prepareStatement(sql);} catch (SQLException e) {e.printStackTrace();}return ps;}// ps与con销毁细节 insert,update,deletepublic void close(){if(ps!=null){try {ps.close();} catch (SQLException e) {e.printStackTrace();}}if(con!=null){try {con.close();} catch (SQLException e) {e.printStackTrace();}}}public void close(ResultSet rs){if(rs!=null){try {rs.close();} catch (SQLException e) {e.printStackTrace();}}close();}
}
7.建表Sql
课程分类表
CREATE TABLE `cclass` (`Ccno` int(255) NOT NULL AUTO_INCREMENT,`Ccname` varchar(255) DEFAULT NULL,PRIMARY KEY (`Ccno`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
用户表
CREATE TABLE `user` (`userno` int(255) NOT NULL AUTO_INCREMENT,`username` varchar(255) NOT NULL,`userpwd` int(10) DEFAULT NULL,`key1` int(10) NOT NULL,PRIMARY KEY (`userno`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
教师表
CREATE TABLE `teacher` (`Tno` int(255) NOT NULL AUTO_INCREMENT,`Tname` varchar(255) DEFAULT NULL,`Cname` varchar(255) DEFAULT NULL,`Kpno` int(255) DEFAULT NULL,`Vidno` int(255) DEFAULT NULL,PRIMARY KEY (`Tno`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
学校表
CREATE TABLE `school` (`Scno` int(255) NOT NULL AUTO_INCREMENT,`Scname` varchar(255) DEFAULT NULL,PRIMARY KEY (`Scno`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
学生选课表
CREATE TABLE `stucouse` (`Stucno` int(255) NOT NULL AUTO_INCREMENT,`Stucname` varchar(255) NOT NULL,PRIMARY KEY (`Stucno`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
通告表
CREATE TABLE `notice` (`Notno` int(255) NOT NULL AUTO_INCREMENT,`Notcno` varchar(255) DEFAULT NULL,PRIMARY KEY (`Notno`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
知识点表
CREATE TABLE `knopoints` (`Kpno` int(255) NOT NULL AUTO_INCREMENT,`Kpname` varchar(255) NOT NULL,PRIMARY KEY (`Kpno`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
学生评价表
CREATE TABLE `evaluate` (`Evacno` int(11) NOT NULL AUTO_INCREMENT,`Evaluate` varchar(255) NOT NULL,`Cname` varchar(255) NOT NULL,PRIMARY KEY (`Evacno`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;