java数据库管理系统课程设计-学生信息管理系统.doc_第1页
java数据库管理系统课程设计-学生信息管理系统.doc_第2页
java数据库管理系统课程设计-学生信息管理系统.doc_第3页
java数据库管理系统课程设计-学生信息管理系统.doc_第4页
java数据库管理系统课程设计-学生信息管理系统.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

此文档收集于网络,如有侵权,请联系网站删除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) JOptio

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论