设计数据库课程设计(Java实现)(共13页).doc
精选优质文档-倾情为你奉上一、 课程设计目的在数据库原理课程基础上,培养学生综合运用数据库知识的能力。学会数据库的设计、规划以及应用程序的开发和调试,使学生掌握客户机/服务器体系结构,学会大型数据库的工作模式。大型数据库管理系统存放于服务器,数据库放在服务器上,学生在客户机上开发应用程序访问服务器上的数据库,并完成应用系统所要求的各项功能,应用程序的开发需要采用当前流行的新软件。二、课程设计内容1 数据库的设计根据学生信息管理系统,经过调查研究,构建合理的数据库。首先构建基本表以及表和表之间的联系,在此基础上构建视图和索引表。2 服务器的组织根据建立的基本表、视图和索引表搭建服务器。3 前端开发工具:java学习并完成编写程序。服务器端:SQL Server20124 开发应用程序利用所学的新软件开发工具进行应用程序的开发。5 连接、调试。三、软硬件环境及系统所采用的体系结构系统的体系结构为C/S结构,具体开发工具为Ecplise ,前台为Java,后台数据库一般为SQL Server2012。四、需求分析通过对学生信息管理的了解,确定本系统具备一下功能。多用户账号登录只要通过用户登录验证后,能对学生的记录信息进行修改,增加,删除等操作。五、系统设计1系统结构图学生信息管理 浏览 查找 修改 增加 删除a.功能模块图 修改增加查看成绩下一条 用户 删除 查询上一条 删除选课查看学科成绩 查询 增加选课 修改2数据库设计学生包含的信息:姓名学科成绩学号 性别 电话学生 宿舍 住址 课程 选择学生 N M用户 密码 用户名Login表USE StudentGOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE dbo.Login(userName nvarchar(20) NOT NULL,password nvarchar(10) NULL, CONSTRAINT PK_Login PRIMARY KEY CLUSTERED (userName ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOStudentIfor表USE StudentGOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE dbo.StudentIfor(code nvarchar(10) NOT NULL,name nvarchar(10) NOT NULL,sex nchar(2) NOT NULL,room nvarchar(10) NOT NULL,address nvarchar(50) NULL,tel nvarchar(11) NULL, CONSTRAINT PK_StudentInfor PRIMARY KEY CLUSTERED (code ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOCrouse表CREATE TABLE dbo.Course(courseID nchar(5) NOT NULL,courseName nvarchar(40) NOT NULL, CONSTRAINT PK_Course PRIMARY KEY CLUSTERED (courseID ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOStudent_Crouse表CREATE TABLE dbo.Student_Course(code nvarchar(10) NOT NULL,courseID nchar(5) NOT NULL,courseGrade float NULL, CONSTRAINT PK_Student_Course PRIMARY KEY CLUSTERED (code ASC,courseID ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGO六、系统的实施系统的实现方法是用java结合SqlServer2012,用java编写前端的用户界面主要的界面代码如下:public class windows implements ActionListenerprivate JFrame frame;private JLabel label;private JTextField textField;private JListlist;private JScrollPane jscrollPane;private DefaultListModel listModel;private JRadioButtonmjRadioButton, fjRadioButton;private ButtonGroupsetButtonGrop;private JButton button;private JButton jbu;private Container con;private ResultSet resultSet;private String sinfor = "* 学号:","* 姓名:","* 性别:","*宿舍:","住址:","电话:"private String binfor = "增加","删除","修改","查找","上一条","下一条"public windows() frame = new JFrame("学生信息管理 ");con = frame.getContentPane();con.setLayout(null);frame.setLocation(350, 150);frame.setSize(7770/15, 6000/15);frame.setResizable(false);textField = new JTextField6;label = new JLabel6;button = new JButton6;for(int i = 0; i < 6; i+)labeli = new JLabel(sinfori);labeli.setLocation(5, 3 + (i * 670/15);labeli.setSize(570/15, 670/15);con.add(labeli);if(i != 2)textFieldi = new JTextField();textFieldi.setSize(200, 470/15);textFieldi.setLocation(770/15,5 +(i * 670/15);con.add(textFieldi);elsemjRadioButton = new JRadioButton("男",false);mjRadioButton.setVisible(true);mjRadioButton.setSize(570/15, 670/15);mjRadioButton.setLocation(970/15,5 + (2 * 670/15);mjRadioButton.addActionListener(this);mjRadioButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);fjRadioButton = new JRadioButton("女",false);fjRadioButton.setSize(570/15, 670/15);fjRadioButton.setLocation(2070/15,5 + (2 * 670/15);fjRadioButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);fjRadioButton.setVisible(true);fjRadioButton.addActionListener(this);setButtonGrop = new ButtonGroup();setButtonGrop.add(mjRadioButton);setButtonGrop.add(fjRadioButton);con.add(mjRadioButton);con.add(fjRadioButton);buttoni = new JButton(binfori);buttoni.setSize(1570/15,370/15);buttoni.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);buttoni.addActionListener(this);if(i <= 2)buttoni.setLocation(240/15 + (i * 2000/15),4300/15);elsebuttoni.setLocation(240/15 + (i-3)* 2000/15), 4300/15 + 450/15);con.add(buttoni);jbu = new JButton("查看成绩");jbu.setSize(1570/15, 800/15);jbu.setLocation(3 * 2000/15, 4300/15);jbu.addActionListener(this);con.add(jbu);select se = new select();resultSet = se.selectTable();listModel = new DefaultListModel();try while(resultSet.next()listModel.addElement(resultSet.getString("code") +" "+ resultSet.getString("name"); catch (SQLException e) e.printStackTrace();se.isDisconnection();list = new JList(listModel);list.addMouseListener(new MouseAdapter()public void mouseClicked(MouseEvent e)if(e.getClickCount() = 2 && list.getSelectedIndex() != -1)clickTwo(list.getSelectedValue(););jscrollPane = new JScrollPane(list);jscrollPane.setSize(200, 250);jscrollPane.setLocation(270, 7);con.add(jscrollPane);frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);应用程序的编制方法是用户点击给出的功能按钮实现对应的功能,按钮响应中调用相应的类及方法,重要代码如下:private void clickTwo(Object value)String str = null;ResultSet re;select se;str = value.toString().substring(0, 8);str.trim();se = new select();re = se.selectCode(str);try textField0.setText( re.getString("code");textField1.setText(re.getString("name");if(re.getString("sex").equals("女 ") = true)fjRadioButton.setSelected(true);elsemjRadioButton.setSelected(true);textField3.setText(re.getString("room");textField4.setText(re.getString("address");textField5.setText(re.getString("tel"); catch (SQLException e) e.printStackTrace();se.isDisconnection();public void actionPerformed(ActionEvent e) String code = null, name = null, sex = "", room = null, address =null, tel = null;if(e.getSource() = button0)code = textField0.getText();name = textField1.getText();Enumeration<AbstractButton> en=setButtonGrop.getElements();while(en.hasMoreElements()AbstractButton ab=en.nextElement();if(ab.isSelected()sex = ab.getText();room = textField3.getText();address = textField4.getText();tel = textField5.getText();code.trim();name.trim();room.trim();address.trim();tel.trim();if(code.equals("")!= true && name.equals("")!=true && room.equals("")!=true && sex.equals("")!= true)if(new addInfor(code, name, sex, address, room, tel).addToDataBase() = true)JOptionPane.showMessageDialog(frame, "增加成功");select se = new select();resultSet = se.selectTable();listModel = new DefaultListModel();try while(resultSet.next()listModel.addElement(resultSet.getString("code") +" "+ resultSet.getString("name"); catch (SQLException e1) e1.printStackTrace();list.setModel(listModel);se.isDisconnection();for(int i = 0; i < 6; i+)if(i != 2)textFieldi.setText("");elseJOptionPane.showMessageDialog(frame, "增加失败,请核对信息");elseJOptionPane.showMessageDialog(frame, "填入信息不全,请核对","警告",JOptionPane.WARNING_MESSAGE);if(e.getSource() = mjRadioButton | e.getSource() = fjRadioButton)sex = e.getActionCommand();if(e.getSource() = button1)String deli = null;deli = JOptionPane.showInputDialog(frame, "请输入删除的学号:");if(deli != null)deli.trim();if(deli.equals("") != true)if(new deleteInfor(deli).studentDel() = true)JOptionPane.showMessageDialog(frame, "删除成功");select se = new select();resultSet = se.selectTable();listModel = new DefaultListModel();try while(resultSet.next()listModel.addElement(resultSet.getString("code") +" "+ resultSet.getString("name"); catch (SQLException e1) e1.printStackTrace();list.setModel(listModel);se.isDisconnection();elseJOptionPane.showMessageDialog(frame, "删除失败,请核对信息");elseJOptionPane.showMessageDialog(frame, "学号不能为空","错误",JOptionPane.ERROR_MESSAGE);if(e.getSource() = button2)code = textField0.getText();name = textField1.getText();Enumeration<AbstractButton> en=setButtonGrop.getElements();while(en.hasMoreElements()AbstractButton ab=en.nextElement();if(ab.isSelected()sex = ab.getText();room = textField3.getText();address = textField4.getText();tel = textField5.getText();code.trim();name.trim();room.trim();address.trim();tel.trim();if(code.equals("")!= true && name.equals("")!=true && room.equals("")!=true && sex.equals("")!= true)if(new update(code,name,sex,room,address,tel).updateStudentIfor() = true)JOptionPane.showMessageDialog(frame, "修改成功");select se = new select();resultSet = se.selectTable();listModel = new DefaultListModel();try while(resultSet.next()listModel.addElement(resultSet.getString("code") +" "+ resultSet.getString("name"); catch (SQLException e1) e1.printStackTrace();list.setModel(listModel);se.isDisconnection();elseJOptionPane.showMessageDialog(frame, "修改失败,请核对信息","错误",JOptionPane.ERROR_MESSAGE);elseJOptionPane.showMessageDialog(frame, "填入信息不全,请核对","警告",JOptionPane.WARNING_MESSAGE);if(e.getSource() = button3)ResultSet s;select sAll;String seach = null;seach = JOptionPane.showInputDialog(frame, "请输入查找的学号:");if(seach != null)seach.trim();if(seach.equals("") != true)sAll = new select();s = sAll.selectCode(seach);try for(int i = 0; i < 6; i+)if(i = 2)if(s.getString(3).equals("男")mjRadioButton.setSelected(true);elsefjRadioButton.setSelected(true);elsetextFieldi.setText(s.getString(i+1); catch (HeadlessException e1) e1.printStackTrace(); catch (SQLException e1) JOptionPane.showMessageDialog(frame, "查找的学生记录不存在:");sAll.isDisconnection();elseJOptionPane.showMessageDialog(frame, "学号不能为空","错误",JOptionPane.ERROR_MESSAGE);if(e.getSource() = button4)JScrollBar jsscroBar;int lis;lis = list.getSelectedIndex();if(lis = -1)list.setSelectedIndex(0);jsscroBar = jscrollPane.getVerticalScrollBar();jsscroBar.setValue(0);elselist.setSelectedIndex(lis - 1);jsscroBar = jscrollPane.getVerticalScrollBar();jsscroBar.setValue(lis * 10 - 1);if(e.getSource() = button5)int lis;JScrollBar jsscroBar;lis = list.getSelectedIndex();list.setSelectedIndex(lis + 1);jsscroBar = jscrollPane.getVerticalScrollBar();jsscroBar.setValue(lis * 10 + 1);if(e.getSource() = jbu)code = textField0.getText();if(code != null)code.trim();if(code.equals("") != true)new crouseFrame(code);else JOptionPane.showMessageDialog(frame, "学号不能为空");七、系统评价及心得体会1改进方案本次实验中,自己设计的程序功能上存在不足的地方,如查询时有限制格式,没有很好的容错性,代码健壮性不足,没有具体的应用价值。同时代码执行的效率也是还有提高的空间的,没有很好的算法加入进去。对于这些问题,需要以后更加深入学习java并且需要有大量的编程经验才能解决的,以后学习的东西还有能多。体会这次数据库 的课程设计,体会最深刻的就是 ,我将面向对象是思想有了更深的了解,之前javaGUI程序设计没有学习,本次要求系统要有界面,用两周时间边自学边编写自己的程序。所以这次收获之一就是java的掌握有所提高并且,在熟悉语言的同时,我也学会了如何使用java连接sqlserver2012数据库,并且掌握了这次主要联系的数据库操作,实现了连接,查询入库删除等功能,虽然还有待提高,但是本次课程设计让我了解了不少,也学习了不少。我感到收获很到。这对我以后的学习或者工作都有很大的帮助。八、参考文献java语言程序设计 北京邮电大学出版社专心-专注-专业