当前位置:文档之家› (完整版)学生信息管理系统数据库java

(完整版)学生信息管理系统数据库java

《数据库原理与应用》课程设计报告选题名称:学生信息管理系统组长:李盟指导教师:汤嘉立设计日期:2016.06.13——2016.06.24学号姓名小组评分教师评分2014144414 李盟902014144415 李玲902014144429 徐兰902014144431 许媛媛906.个人工作报告除上一步骤要求的完整文档外,每个人需陈述自己所承担的工作、在讨论中的个人见解,提供个人所承担工作的有关文档(可能是不完整的),并对个人的工作情况、收获等进行总结。

(1)承担的工作及贡献●需求分析阶段●概念模型设计阶段局部E-R模型:整体E-R模型:●逻辑模型设计阶段Student(sno,sn,sa,ss,sd)Course(cno,cn,pcno)Sc(sno,cno,g)Unpw(un,pw,qx)●物理模型设计阶段s(学生信息表)字段名称数据类型描述sno char (10) 学号,关键字sn char (20) 姓名sa int 年龄ss char (10) 性别sd char (10) 院系c(课程信息表)字段名称数据类型描述cno char (10) 课程号,关键字cn char (30) 课程名pcno char (10) 先行课程号sc(选课信息表)字段名称数据类型描述sno char (10) 学号,关键字cno char (10) 课程号,关键字g int 成绩unpw(用户信息表)字段名称数据类型描述un char (10) 用户名,关键字pw char (10) 密码qx int 角色1.视图:2.s(学生信息表)3.c(课程信息表)4.sc(选课信息表)5.unpw(用户信息表) 实施和实现阶段附件1 系统实施一、登录界面图片:代码:package li;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;class DLFrame extends JFrame implements ActionListener, ItemListener {// 登录界面JPanel p1 = null;JPanel p2 = null;JPanel p3 = null;JLabel userName = new JLabel("用户:");JTextField txtUser = new JTextField();JLabel password = new JLabel("密码:");JPasswordField txtPwd = new JPasswordField(6);JLabel role = new JLabel("角色:");JComboBox cbrole = new JComboBox();JButton btnLogin = new JButton("登录");JButton btncz = new JButton("重置");JButton btnCancel = new JButton("取消");JLabel imageLabel;Icon image;static int OK = 1;static int CANCEL = 0;int actionCode = 0;Connection con = null;Statement stmt = null;ResultSet rs = null;int qxian = 0;public DLFrame() {// 构造方法super("登录界面");p1 = new JPanel();p2 = new JPanel();p3 = new JPanel();cbrole.addItem("管理员");cbrole.addItem("学生");image = new ImageIcon("Tulips.jpg");imageLabel = new JLabel(image);p1.add(imageLabel);this.setLayout(new FlowLayout());this.setBounds(100, 100, 246, 345);p2.setLayout(new GridLayout(4, 2));p2.add(userName);p2.add(txtUser);p2.add(password);p2.add(txtPwd);p2.add(role);p2.add(cbrole);p3.add(btnLogin);p3.add(btncz);p3.add(btnCancel);this.add(p1);this.add(p2);this.add(p3);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.show();btnLogin.addActionListener(this);cbrole.addItemListener(this);btncz.addActionListener(this);btnCancel.addActionListener(this);}public void connDB() { // 连接数据库try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");} catch (ClassNotFoundException e) {e.printStackTrace();}try {con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433; DatabaseName=student","sa", "123");stmt = con.createStatement();} catch (SQLException e) {e.printStackTrace();}}public void closeDB() // 关闭连接{try {stmt.close();con.close();} catch (SQLException e) {e.printStackTrace();}}public void itemStateChanged(ItemEvent e) {if (e.getStateChange() == ItemEvent.SELECTED) {JComboBox jcb = (JComboBox) e.getSource();qxian = jcb.getSelectedIndex();}}public void actionPerformed(ActionEvent e) {Object source = e.getSource();String un = null;String pw = null;boolean success = false;// 用于判断是否登录成功if (source == btnLogin) {if (txtUser.getText().equals("") || txtPwd.getText().equals("")) {// 判断是否输入了用户名和密码JOptionPane.showMessageDialog(null, "登录名和密码不能为空!");} else {this.connDB();try {rs = stmt.executeQuery("select * from unpw where qx="+ qxian);while (rs.next()) {un = rs.getString("un").trim();pw = rs.getString("pw").trim();if (txtUser.getText().equals(un)) {if (txtPwd.getText().equals(pw)) {actionCode = OK;this.setVisible(false);if (qxian == 0) {new ManagerFrane();// 进入管理员界面}if (qxian == 1) {new StudentFrame();// 进入学生界面}success = true;break;} else {JOptionPane.showMessageDialog(null, "密码错误!");txtPwd.setText("");success = true;}}}if (!success) {JOptionPane.showMessageDialog(null, "登录名错误!");txtUser.setText("");txtPwd.setText("");}} catch (SQLException e1) {e1.printStackTrace();}}} else if (source == btncz) {txtUser.setText("");txtPwd.setText("");} else if (source == btnCancel) {System.exit(0);}}public static void main(String[] args){JPanel mainp=new JPanel();DLFrame student=new DLFrame();}}二、管理员界面图片:代码:package li;import java.awt.*;import java.awt.event.*;import javax.swing.*;class ManagerFrane extends JFrame implements ActionListener {// 管理员界面JPanel p1 = new JPanel();JPanel p2 = new JPanel();JButton btns = new JButton("学生信息管理");JButton btnc = new JButton("课程信息管理");JButton btnsc = new JButton("选课信息管理");JButton btng = new JButton("成绩信息管理");JButton btnu = new JButton("用户信息管理");JButton btnClose = new JButton("退出管理系统");JLabel l = new JLabel("管理员");ManagerFrane() {// 构造方法super("学生信息管理系统");setSize(350, 200);add("North", p1);add("Center", p2);p1.add(l);p2.add(btns);p2.add(btnc);p2.add(btnsc);p2.add(btng);p2.add(btnu);p2.add(btnClose);btns.addActionListener(this);btnc.addActionListener(this);btnsc.addActionListener(this);btng.addActionListener(this);btnu.addActionListener(this);btnClose.addActionListener(this);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);show();}public void actionPerformed(ActionEvent e) {if (e.getActionCommand() == "学生信息管理")new SM().display();if (e.getActionCommand() == "课程信息管理") {new CM("课程信息管理").display();}if (e.getActionCommand() == "选课信息管理") {new SCM("选课信息管理").display();}if (e.getActionCommand() == "成绩信息管理") {new GM("成绩信息管理").display();}if (e.getActionCommand() == "用户信息管理") {new PM("用户信息管理").display();}if (e.getActionCommand() == "退出管理系统") {System.exit(0);}}}(一)学生信息管理代码:class SM extends JFrame implements ActionListener {// 学生信息管理JPanel p = new JPanel();JButton btnAdd = new JButton("增加");JButton btnDelete = new JButton("删除");JButton btnAlter = new JButton("修改");JButton btnSearch = new JButton("查询");JButton btnDisplay = new JButton("显示");JMenuBar mb = new JMenuBar();JPanel p1 = new JPanel();;JTable sTable;JScrollPane scroll;Connection con = null;Statement stmt = null;ResultSet rs = null;Object[][] playerInfo;SSelect sst;String mxh = null;boolean bstd = false;SM() {// 构造方法super("学生信息管理");add("South", p);this.add("Center", p1);mb.add(btnAdd);mb.add(btnDelete);mb.add(btnAlter);mb.add(btnSearch);mb.add(btnDisplay);SM(SSelect sst) {// 构造方法super("学生信息管理");this.sst = sst;bstd = true;add("South", p);this.add("Center", p1);mb.add(btnAdd);mb.add(btnDelete);mb.add(btnAlter);mb.add(btnSearch);mb.add(btnDisplay);this.connDB();this.setBounds(200, 200, 400, 260);btnAdd.addActionListener(this);btnDelete.addActionListener(this);btnAlter.addActionListener(this);btnSearch.addActionListener(this);btnDisplay.addActionListener(this);this.setJMenuBar(mb);// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false);show();}public void display() {// 显示所有学生的基本信息int i = 0;int j = 0;int k = 0;List al = new ArrayList();try {rs = stmt.executeQuery("select * from s");while (rs.next()) { // 找出表中的记录数赋给ial.add(rs.getString("sno"));al.add(rs.getString("sn"));al.add(rs.getString("ss"));al.add(rs.getInt("sa"));al.add(rs.getString("sd"));i++;}} catch (SQLException e) {e.printStackTrace();}playerInfo = new Object[i][5];String[] columnNames = { "学号", "姓名", "年龄", "性别", "院系" };try {rs = stmt.executeQuery("select * from s order by sno");while (rs.next()) {playerInfo[j][0] = rs.getString("sno");playerInfo[j][1] = rs.getString("sn");playerInfo[j][2] = rs.getInt("sa");playerInfo[j][3] = rs.getString("ss");playerInfo[j][4] = rs.getString("sd");j++;}} catch (SQLException e) {e.printStackTrace();}sTable = new JTable(playerInfo, columnNames);// 创建网格p1.add(sTable);scroll = new JScrollPane(sTable);this.add(scroll);}public void delete() {// 删除某个学生的基本信息String xh = null;String xm = null;int nl = 0;String xb = null;String yx = null;int row = -1;row = sTable.getSelectedRow();if (row == -1) {// 判断要删除的信息是否被选中JOptionPane.showMessageDialog(null, "请选择要删除的记录!");} else {if (!bstd) {// 判断选择的是不是查询后的结果int j1 = 0;try {rs = stmt.executeQuery("select * from s");while (rs.next() && j1 <= row) {// 找出当前被选中的记录在数据库中的对应xh = rs.getString("sno");xm = rs.getString("sn");nl = rs.getInt("sa");xb = rs.getString("ss");yx = rs.getString("sd");j1++;}} catch (SQLException e) {e.printStackTrace();}int i1 = 0;try {int rs1 = stmt.executeUpdate("delete from s where sno='"+ xh + "'"); // 删除数据库中当前被选中的记录stmt.executeUpdate("delete from unpw where un='" + xh + "'");// 删除对应的用户表中的记录JOptionPane.showMessageDialog(null, "记录删除成功!");this.dispose();new SM().display();} catch (SQLException e) {e.printStackTrace();}} else {try {int rs1 = stmt.executeUpdate("delete from s where sno='"+ mxh + "'");stmt.executeUpdate("delete from unpw where un='" + mxh+ "'");JOptionPane.showMessageDialog(null, "记录删除成功!");this.dispose();new SM().display();} catch (SQLException e) {e.printStackTrace();}}}}public void update() {// 修改某个学生的基本信息String xh = null;String xm = null;int nl = 0;String xb = null;String yx = null;int row = -1;row = sTable.getSelectedRow();if (row == -1) {JOptionPane.showMessageDialog(null, "请选择要修改的记录!");} else {int j1 = 0;try {if (!bstd) {// 判断选择的是不是查询后的结果rs = stmt.executeQuery("select * from s");} else {rs = stmt.executeQuery("select * from s where sno='" + mxh+ "'");}while (rs.next() && j1 <= row) {// 找出当前被选中的记录在数据库中的对应xh = rs.getString("sno");xm = rs.getString("sn");nl = rs.getInt("sa");xb = rs.getString("ss");yx = rs.getString("sd");j1++;}} catch (SQLException e) {e.printStackTrace();}SAdd sadd = new SAdd(xb, yx);sadd.setTitle("修改");sadd.tsno.setText(xh);sadd.tsname.setText(xm);sadd.tsage.setText("" + nl);sadd.tsno.setEnabled(false);this.dispose();}}public void select() {// 显示某个查询的结果mxh = sst.xh;playerInfo = new Object[1][5];String[] columnNames = { "学号", "姓名", "年龄", "性别", "院系" };try {rs = stmt.executeQuery("select * from s where sno='" + mxh + "'");while (rs.next()) {playerInfo[0][0] = rs.getString("sno");playerInfo[0][1] = rs.getString("sn");playerInfo[0][2] = rs.getInt("sa");playerInfo[0][3] = rs.getString("ss");playerInfo[0][4] = rs.getString("sd");}} catch (SQLException e) {e.printStackTrace();}if (playerInfo[0][1] == null) {this.dispose();JOptionPane.showMessageDialog(null, "学号不存在!");new SM().display();} else {sTable = new JTable(playerInfo, columnNames);// 创建网格p1.add(sTable);scroll = new JScrollPane(sTable);this.add(scroll);}}public void actionPerformed(ActionEvent e) {if (e.getActionCommand() == "增加") {new SAdd("男", "计科系");this.dispose();}if (e.getActionCommand() == "删除") {this.delete();}if (e.getActionCommand() == "修改") {this.update();}if (e.getActionCommand() == "查询") {sst = new SSelect("学号:");this.dispose();}if (e.getActionCommand() == "显示") {this.dispose();new SM().display();}}}1.用于学生信息管理中增加或修改某条记录的界面图片:代码:class SAdd extends JFrame implements ActionListener, ItemListener {// 用于学生信息管理中增加或修改某条记录的界面JLabel lsno = new JLabel("学号:");JLabel lsname = new JLabel("姓名:");JLabel lssex = new JLabel("性别:");JLabel lsage = new JLabel("年龄:");JLabel lsdept = new JLabel("院系:");JTextField tsno = new JTextField(14);JTextField tsname = new JTextField(14);JComboBox cbssex = new JComboBox();JTextField tsage = new JTextField(14);JComboBox cbsdept = new JComboBox();JButton btnOK = new JButton(" 确定"); JButton btnCancel = new JButton(" 取消"); JPanel p = new JPanel();Connection con = null;Statement stmt = null;ResultSet rs = null;String xb = "男";String yx = "计科系";boolean isNewsm = true;// 用于判断是否显示学生管理的界面public SAdd(String xb, String yx) {// 构造方法this.xb = xb;this.yx = yx;this.setTitle("增加");this.setBounds(200, 200, 220, 210);if (xb.trim().equals("男")) {cbssex.addItem("男");cbssex.addItem("女");} else {cbssex.addItem("女");cbssex.addItem("男");}if (yx.trim().equals("计科系")) {cbsdept.addItem("计科系");cbsdept.addItem("物理系");cbsdept.addItem("数学系");cbsdept.addItem("外语系");}if (yx.trim().equals("物理系")) {cbsdept.addItem("物理系");cbsdept.addItem("计科系");cbsdept.addItem("数学系");cbsdept.addItem("外语系");}if (yx.trim().equals("外语系")) {cbsdept.addItem("外语系");cbsdept.addItem("计科系");cbsdept.addItem("物理系");cbsdept.addItem("数学系");}if (yx.trim().equals("数学系")) {cbsdept.addItem("数学系");cbsdept.addItem("计科系");cbsdept.addItem("物理系");cbsdept.addItem("外语系");}p.setLayout(new FlowLayout(FlowLayout.LEFT));p.add(lsno);p.add(tsno);p.add(lsname);p.add(tsname);p.add(lsage);p.add(tsage);p.add(lssex);p.add(cbssex);p.add(lsdept);p.add(cbsdept);p.add(btnOK);p.add(btnCancel);this.add(p);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);cbssex.addItemListener(this);cbsdept.addItemListener(this);btnOK.addActionListener(this);btnCancel.addActionListener(this);this.show();}public void insertst() { // 插入记录String xh = null;String xm = null;int nl = 0;xh = tsno.getText();xm = tsname.getText();try {nl = Integer.parseInt((String) tsage.getText());if (this.getTitle() == "修改") {// 如果是修改记录,先删除再增加try {this.connDB();int rs1 = stmt.executeUpdate("delete from s where sno='"+ xh + "'");} catch (SQLException e) {e.printStackTrace();}}String str = "insert into s values('" + xh + "','" + xm + "'," + nl+ ",'" + xb + "','" + yx + "')";this.connDB();// 连接数据库try {stmt.executeUpdate(str);JOptionPane.showMessageDialog(null, this.getTitle() + "成功!","提示", RMATION_MESSAGE, new ImageIcon("menu4.gif"));this.setVisible(false);} catch (SQLException e) {JOptionPane.showMessageDialog(null, "学号已存在!");tsno.setText("");}} catch (NumberFormatException e) {// 判断年龄是否为数字JOptionPane.showMessageDialog(null, "年龄必须是整数!");tsage.setText("");isNewsm = false;}if (this.getTitle() == "增加") {// 如果是增加记录,对应的用户表中也增加一条记录try {stmt.executeUpdate("insert into unpw values('" + xh + "','"+ xh + "'," + 1 + ")");} catch (NullPointerException e) {} catch (SQLException e) {// e.printStackTrace();}}}public void actionPerformed(ActionEvent e) {if (e.getActionCommand() == " 确定") {this.insertst();if (isNewsm) {new SM().display();}isNewsm = true;}if (e.getActionCommand() == " 取消") {this.setVisible(false);new SM().display();}}public void itemStateChanged(ItemEvent e) { // 下拉框的监听if (e.getStateChange() == ItemEvent.SELECTED) {JComboBox jcb = (JComboBox) e.getSource();if ((jcb.getSelectedItem() == "男")|| (jcb.getSelectedItem() == "女")) {xb = (String) jcb.getSelectedItem();} else {yx = (String) jcb.getSelectedItem();}}}}2.用于学生基本信息管理中查询时输入学号的界面图片:代码:public class SSelect extends JFrame implements ActionListener {// 用于学生基本信息管理中查询时输入学号的界面JLabel ltitle = null;JTextField tsno = new JTextField(8);JButton btnOK = new JButton("确定");JPanel p = new JPanel();String xh = null;public SSelect(String str) {// 构造方法ltitle = new JLabel(str);p.add(ltitle);p.add(tsno);p.add(btnOK);add(p);this.setBounds(300, 280, 200, 160);btnOK.addActionListener(this);this.setResizable(false);this.show();}public void actionPerformed(ActionEvent e) {xh = tsno.getText();// 取得当前输入学号的值if (xh.equals("")) {// 判断是否输入了学号JOptionPane.showMessageDialog(null, "学号不能为空,请重新输入!");} else {this.dispose();new SM(this).select();}}}(二)课程信息管理图片:代码:class CM extends JFrame implements ActionListener {// 课程信息管理JPanel p = new JPanel();JButton btnAdd = new JButton("增加");JButton btnDelete = new JButton("删除");JButton btnAlter = new JButton("修改");JButton btnSearch = new JButton("查询");JButton btnDisplay = new JButton("显示");JMenuBar mb = new JMenuBar();JPanel p1 = new JPanel();;JTable sTable;JScrollPane scroll;Connection con = null;Statement stmt = null;ResultSet rs = null;Object[][] playerInfo;CSelect cst;String mkch = null;boolean bstd = false;CM(String title) {// 构造方法super(title);add("South", p);this.add("Center", p1);mb.add(btnAdd);mb.add(btnDelete);mb.add(btnAlter);mb.add(btnSearch);mb.add(btnDisplay);CM(CSelect cst, String title) {// 构造方法super(title);this.cst = cst;bstd = true;add("South", p);this.add("Center", p1);mb.add(btnAdd);mb.add(btnDelete);mb.add(btnAlter);mb.add(btnSearch);mb.add(btnDisplay);this.connDB();this.setBounds(200, 200, 400, 260);btnAdd.addActionListener(this);btnDelete.addActionListener(this);btnAlter.addActionListener(this);btnSearch.addActionListener(this);btnDisplay.addActionListener(this);this.setJMenuBar(mb);// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false);show();}public void display() {// 显示所有的课程信息int i = 0;int j = 0;int k = 0;List al = new ArrayList();try {rs = stmt.executeQuery("select * from c");while (rs.next()) {// 找出表中的记录数赋给ial.add(rs.getString("cno"));al.add(rs.getString("cn"));al.add(rs.getString("pcno"));i++;}} catch (SQLException e) {e.printStackTrace();}playerInfo = new Object[i][3];String[] columnNames = { "课程号", "课程名", "先行课程号" };try {rs = stmt.executeQuery("select * from c order by cno");while (rs.next()) {playerInfo[j][0] = rs.getString("cno");playerInfo[j][1] = rs.getString("cn");playerInfo[j][2] = rs.getString("pcno");j++;}} catch (SQLException e) {e.printStackTrace();}sTable = new JTable(playerInfo, columnNames);// 创建网格p1.add(sTable);scroll = new JScrollPane(sTable);this.add(scroll);}public void connDB() { // 连接数据库try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");} catch (ClassNotFoundException e) {e.printStackTrace();}try {con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433; DatabaseName=student","sa", "123");stmt = con.createStatement();} catch (SQLException e) {e.printStackTrace();}}public void closeDB() // 关闭连接{try {stmt.close();con.close();} catch (SQLException e) {e.printStackTrace();}}public void delete() {// 删除某个课程信息String kch = null;String kcm = null;String xxkch = null;int row = -1;row = sTable.getSelectedRow();if (row == -1) {// 判断要删除的信息是否被选中JOptionPane.showMessageDialog(null, "请选择要删除的记录!");} else {if (!bstd) {// 判断选择的是不是查询后的结果int j1 = 0;try {rs = stmt.executeQuery("select * from c");while (rs.next() && j1 <= row) {// 找出当前被选中的记录在数据库中的对应kch = rs.getString("cno");kcm = rs.getString("cn");xxkch = rs.getString("pcno");j1++;}} catch (SQLException e) {e.printStackTrace();}int i1 = 0;try {int rs1 = stmt.executeUpdate("delete from c where cno='"+ kch + "'");// 删除数据库中当前被选中的记录JOptionPane.showMessageDialog(null, "记录删除成功!");this.dispose();new CM("课程信息管理").display();} catch (SQLException e) {e.printStackTrace();}} else {try {int rs1 = stmt.executeUpdate("delete from c where cno='"+ mkch + "'");// 删除数据库中当前被选中的记录JOptionPane.showMessageDialog(null, "记录删除成功!");this.dispose();new CM("课程信息管理").display();} catch (SQLException e) {e.printStackTrace();}}}}public void update() {// 修改某个课程记录String kch = null;String kcm = null;String xxkch = null;int row = -1;row = sTable.getSelectedRow();if (row == -1) {JOptionPane.showMessageDialog(null, "请选择要修改的记录!");} else {int j1 = 0;try {if (!bstd) {// 判断选择的是不是查询后的结果rs = stmt.executeQuery("select * from c");} else {rs = stmt.executeQuery("select * from c where cno='" + mkch+ "'");}while (rs.next() && j1 <= row) {// 找出当前被选中的记录在数据库中的对应kch = rs.getString("cno");kcm = rs.getString("cn");xxkch = rs.getString("pcno");j1++;}} catch (SQLException e) {e.printStackTrace();}CAdd cadd = new CAdd();cadd.setTitle("修改");cadd.tcno.setText(kch);cadd.tcname.setText(kcm);cadd.tpcno.setText(xxkch);cadd.tcno.setEnabled(false);this.dispose();}}public void select() {// 显示某个查询的结果mkch = cst.kch;playerInfo = new Object[1][3];String[] columnNames = { "课程号", "课程名", "先行课程号" };try {rs = stmt.executeQuery("select * from c where cno='" + mkch + "'");while (rs.next()) {playerInfo[0][0] = rs.getString("cno");playerInfo[0][1] = rs.getString("cn");playerInfo[0][2] = rs.getString("pcno");}} catch (SQLException e) {e.printStackTrace();}if (playerInfo[0][1] == null) {this.dispose();JOptionPane.showMessageDialog(null, "课程号不存在!");new CM("课程信息管理").display();} else {sTable = new JTable(playerInfo, columnNames);// 创建网格p1.add(sTable);scroll = new JScrollPane(sTable);this.add(scroll);}}public void actionPerformed(ActionEvent e) {if (e.getActionCommand() == "增加") {new CAdd();this.dispose();}if (e.getActionCommand() == "删除") {this.delete();}if (e.getActionCommand() == "修改") {this.update();}if (e.getActionCommand() == "查询") {cst = new CSelect();this.dispose();}if (e.getActionCommand() == "显示") {this.dispose();new CM("课程信息管理").display();}}}3.用于课程信息管理中增加或修改某条记录的界面图片:代码:class CAdd extends JFrame implements ActionListener{// 用于课程信息管理中增加或修改某条记录的界面JLabel lcno = new JLabel("课程号:");JLabel lcname = new JLabel("课程名:");JLabel lpcno = new JLabel("先行课程号:");JTextField tcno = new JTextField(10);JTextField tcname = new JTextField(10);JTextField tpcno = new JTextField(10);JButton btnOK = new JButton("确定");JButton btnCancel = new JButton("取消");JPanel p = new JPanel();Connection con = null;Statement stmt = null;ResultSet rs = null;boolean isNewsm = true;// 用于判断是否显示课程信息管理的界面public CAdd() {// 构造方法this.setTitle("增加");this.setBounds(200, 200, 146, 235);p.setLayout(new FlowLayout(FlowLayout.LEFT));p.add(lcno);p.add(tcno);p.add(lcname);p.add(tcname);p.add(lpcno);p.add(tpcno);p.add(btnOK);p.add(btnCancel);this.add(p);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btnOK.addActionListener(this);btnCancel.addActionListener(this);this.show();}public void insertst() { // 插入记录String kch = null;String kcm = null;String xxkch=null;kch = tcno.getText();kcm = tcname.getText();xxkch=tpcno.getText();if (this.getTitle() == "修改") {// 如果是修改记录,先删除再增加try {this.connDB();int rs1 = stmt.executeUpdate("delete from c where cno='"+ kch + "'");} catch (SQLException e) {e.printStackTrace();}}String str = "insert into c values('" + kch + "','" + kcm + "','"+ xxkch + "')";public void actionPerformed(ActionEvent e) {if (e.getActionCommand() == "确定") {this.insertst();if (isNewsm) {new CM("课程信息管理").display();}isNewsm = true;}if (e.getActionCommand() == "取消") {this.setVisible(false);new CM("课程信息管理").display();}}}4.用于课程信息管理中查询时输入课程号的界面图片:代码:public class CSelect extends JFrame implements ActionListener {// 用于课程信息管理中查询时输入课程号的界面JLabel ltitle = new JLabel("课程号:");JTextField tcno = new JTextField(8);JButton btnOK = new JButton("确定");JPanel p = new JPanel();String kch = null;public CSelect() { // 构造方法p.add(ltitle);p.add(tcno);p.add(btnOK);add(p);this.setBounds(300, 280, 200, 160);btnOK.addActionListener(this);this.setResizable(false);this.show();}public void actionPerformed(ActionEvent e) {kch = tcno.getText();// 取得当前输入课程号的值if (kch.equals("")) {// 判断是否输入了课程号JOptionPane.showMessageDialog(null, "课程号不能为空,请重新输入!");} else {this.dispose();new CM(this, "课程信息管理").select();}}}(三)选课信息管理图片:代码:。

相关主题