java数据库管理系统课程设计学生信息管理系统.doc
Java课程设计姓 名:学 号:班 级:学 院:指导教师:目录1. 题目简介2. 程序概要.3. 程序函数简介.4. 源代码5. 运行截图.6. 心得体会.1题目简介题目简介:要求基于数据库管理系统,建立一个学生信息管理系统,有简单的显示、更新、插入等基本功能。还有程序需有窗口,也就是运行界面中要含有窗口。程序尽量简单,但功能得全面,界面做到尽善尽美!2.程序概要程序概要:本程序中含有一个public类,三个一般类。其主函数在public类中,一般类中每个类实现一个功能。在主函数中调用一般类中的函数,实现不同的功能。每个一般类也是建立在窗口上的,其中运用了窗口,组件,按钮,布局等多种知识。3.程序函数简介public static void main(String args ).主函数class DatabaseWin extends JFrame implements ActionListener该类实现主要窗口的建立DatabaseWin().建立窗口,添加窗口组件public void actionPerformed(ActionEvent e).实现监视class InsertRecord extends JDialog implements ActionListener负责插入的类InsertRecord(String s)实现插入功能class ShowRecord extends JDialog implements ActionListener负责显示的类ShowRecord(String title).实现显示功能class ModifyRecord extends JDialog implements ActionListener.责更新的类ModifyRecord(String s).实现更新功能4.源代码import javax.swing.*; import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.border.*;public class Mykcsj public static void main(String args ) try Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); catch(ClassNotFoundException e) System.out.println(""+e); DatabaseWin win=new DatabaseWin(); class DatabaseWin extends JFrame implements ActionListener/主窗口 JMenuBar menubar; JMenu menu; JMenuItem itemShow,itemUpdate,itemInsert; ShowRecord showRecord; ModifyRecord modifyRecord; InsertRecord insertRecord; DatabaseWin() menubar=new JMenuBar(); menu=new JMenu("操作数据库"); itemShow=new JMenuItem("显示记录"); itemUpdate=new JMenuItem("更新记录"); itemInsert=new JMenuItem("插入记录"); itemShow.addActionListener(this); itemUpdate.addActionListener(this); itemInsert.addActionListener(this); menu.add(itemShow); menu.add(itemUpdate); menu.add(itemInsert); menubar.add(menu); showRecord=new ShowRecord("显示记录对话框"); modifyRecord=new ModifyRecord("修改记录对话框"); insertRecord=new InsertRecord("插入记录对话框"); setJMenuBar(menubar); setBounds(100,100,370,250); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); public void actionPerformed(ActionEvent e) if(e.getSource()=itemShow) showRecord.setVisible(true); else if(e.getSource()=itemUpdate) modifyRecord.setVisible(true); else if(e.getSource()=itemInsert) insertRecord.setVisible(true); class InsertRecord extends JDialog implements ActionListener /负责插入记录的类 JLabel hintLabel; Object name="学号","姓名","出生日期","身高" Object a=new Object14; JTable table; JButton enterInsert; Connection con; Statement sql; ResultSet rs; String num; InsertRecord(String s) setTitle(s); hintLabel=new JLabel("输入新记录:"); table=new JTable(a,name); enterInsert=new JButton("插入新记录"); setLayout(null); Box baseBox=Box.createHorizontalBox(); baseBox.add(hintLabel); baseBox.add(new JScrollPane(table); baseBox.add(enterInsert); add(baseBox); baseBox.setBounds(10,40,600,38); enterInsert.addActionListener(this); setBounds(120,160,700,200); public void actionPerformed(ActionEvent e) try con=DriverManager.getConnection("jdbc:odbc:hello","",""); sql=con.createStatement(); int k=sql.executeUpdate ("INSERT INTO message VALUES('"+ a00+"','"+a01+"','"+a02+"','"+a03+"')"); if(k=1) JOptionPane.showMessageDialog (this,"插入记录成功","成功",JOptionPane.PLAIN_MESSAGE); con.close(); catch(SQLException ee) JOptionPane.showMessageDialog (this,"插入记录失败"+ee,"失败",JOptionPane.ERROR_MESSAGE); class ShowRecord extends JDialog implements ActionListener/负责显示记录的类 JTable table; Object a; Object name="学号","姓名","出生日期","身高" JButton showRecord; Connection con; Statement sql; ResultSet rs; ShowRecord(String title) setTitle(title); showRecord=new JButton("显示记录"); showRecord.addActionListener(this); add(showRecord,BorderLayout.NORTH); setBounds(200,60,400,250); public void actionPerformed(ActionEvent e) try con=DriverManager.getConnection("jdbc:odbc:hello","",""); sql=con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); rs=sql.executeQuery("SELECT * FROM message "); rs.last(); int lastNumber=rs.getRow(); a=new ObjectlastNumber4; int k=0; rs.beforeFirst(); while(rs.next() ak0=rs.getString(1); ak1=rs.getString(2); ak2=rs.getDate(3); ak3=rs.getString(4); k+; con.close(); catch(SQLException ee) System.out.println(ee); table=new JTable(a,name); getContentPane().removeAll(); validate(); add(showRecord,BorderLayout.NORTH); add(new JScrollPane(table),BorderLayout.CENTER); validate(); class ModifyRecord extends JDialog implements ActionListener /负责更新记录的类 JLabel hintLabel; JTextField inputNumber; Object name="姓名","出生日期","身高" Object a=new Object13; JTable table; JButton enterModify; Connection con; Statement sql; ResultSet rs; String num; ModifyRecord(String s) setTitle(s); hintLabel=new JLabel("输入学号(回车确认):"); inputNumber=new JTextField(20); table=new JTable(a,name); enterModify=new JButton("更新记录"); setLayout(null); Box baseBox=Box.createHorizontalBox(); baseBox.add(hintLabel); baseBox.add(inputNumber); baseBox.add(new JScrollPane(table); baseBox.add(enterModify); add(baseBox); baseBox.setBounds(10,40,600,38); inputNumber.addActionListener(this); enterModify.addActionListener(this); setBounds(20,60,700,200); public void actionPerformed(ActionEvent e) if(e.getSource()=inputNumber) try num=inputNumber.getText().trim(); con=DriverManager.getConnection("jdbc:odbc:hello","",""); sql=con.createStatement(); rs=sql.executeQuery("SELECT * FROM message WHERE 学号='"+num+"'"); boolean boo=rs.next(); if(boo=false) JOptionPane.showMessageDialog (this,"学号不存在","提示",JOptionPane.WARNING_MESSAGE); else a00=rs.getString(2); a01=rs.getDate(3).toString(); a02=rs.getString(4); table.repaint(); con.close(); catch(SQLException ee) System.out.println(ee); if(e.getSource()=enterModify) try con=DriverManager.getConnection("jdbc:odbc:hello","",""); sql=con.createStatement(); sql.executeUpdate ("UPDATE message SET 姓名='"+a00+ "',出生日期='"+a01+ "',身高='"+a02+"'WHERE 学号='"+num+"'"); JOptionPane.showMessageDialog (this,"更新成功","成功",JOptionPane.PLAIN_MESSAGE); con.close(); catch(SQLException ee) JOptionPane.showMessageDialog (this,"更新失败"+ee,"失败",JOptionPane.ERROR_MESSAGE); 5.运行截图插入前:插入后:更新前:更新后:7. 设计心得其实这次课程设计相对于前几次的课程设计相对容易的多,因为我们刚学完就开始做这个,所以很多东西都很清楚。但是作为一个课程设计,也有很多难点。刚开始写的时候很顺利,但随着功能得加大,越来越多的东西需要我去查资料,问同学,问老师。这次课程设计大概耗时半个月,设计结果自己还算满意。这次课程设计虽然花了很多时间,但也学到了很多东西。这就是课程设计的目的,我想我已经做到,也已经深深体会到了.