ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:326.47KB ,
资源ID:23538613      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/23538613.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(java学生管理系统.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

java学生管理系统.docx

1、java学生管理系统Java学生管理系统能够题目及简介在例12-3的基础上完善程序,做图形界面,在其中有多个选项“添加”、“修改”、“删除”、“查询”等,根据用户选择的功能再输入相应的数据并完成相关功能。开发环境概述java开发工具eclipse,SQL server 2005;一:描述 1.主界面上直接显示数据库中的所有数据,有添加、删除、修改、查询各个按钮2.查询在主界面上实现。根据学号和姓名查询。没有新建类,代码在主界面类里。3.修改和添加都新建了一个类(update和add),生成一个新的窗口,以实现功能。删除的代码比较简单,也在主界面类里。4.专门新建了一个连接类connection

2、db,以实现与数据库的连接。里面还包含了sql语句。5.关于JTable 的实现,专门建了一个类model,完成对JTable的初始化。二:界面截图1.主界面2.查询3.添加4.修改 5.删除三:源代码:add类:import java.awt.BorderLayout;import java.awt.Frame;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swin

3、g.JComboBox;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class add extends JDialog implements ActionListener /定义组件 JPanel jp1,jp2,jp3; JLabel jl1,jl2,jl3,jl4,jl5; JButton j

4、b1,jb2; JTextField jtf1,jtf2,jtf4; JComboBox jc3,jc5; /构造器 public add(Frame owner,String title,boolean modal) super(owner,title,modal); /定义jp1 jp1 = new JPanel(); jl1 = new JLabel(学号); jl2 = new JLabel(姓名); jl3 = new JLabel(性别); jl4 = new JLabel(出生年月); jl5 = new JLabel(专业); jp1.add(jl1); jp1.add(jl2

5、); jp1.add(jl3); jp1.add(jl4); jp1.add(jl5); jp1.setLayout(new GridLayout(5,1); /定义jp2 jp2 = new JPanel(); jtf1 = new JTextField(9); jtf2 = new JTextField(8); jtf4 = new JTextField(8); jc3 = new JComboBox(); jc3.addItem(男); jc3.addItem(女); jc5 = new JComboBox(); jc5.addItem(计算); jc5.addItem(信管); jc5

6、.addItem(地信); jc5.addItem(日语); jp2.add(jtf1); jp2.add(jtf2); jp2.add(jc3); jp2.add(jtf4); jp2.add(jc5); jp2.setLayout(new GridLayout(5,1); /定义jp3 jp3 = new JPanel(); jb1 = new JButton(确定); jb2 = new JButton(取消); jp3.add(jb1); jp3.add(jb2); /注册监听 jb1.addActionListener(this); jb2.addActionListener(thi

7、s); this.add(jp1,BorderLayout.WEST); this.add(jp2,BorderLayout.CENTER); this.add(jp3,BorderLayout.SOUTH); /定义窗口 this.setSize(300,300); this.setLocation(250, 250); this.setVisible(true); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); /响应函数 public void actionPerformed(ActionEvent e) if(e.getS

8、ource().equals(jb1) String str = new String5; str0 = jtf1.getText(); str1 = jtf2.getText(); str2 = jc3.getSelectedItem().toString().trim(); str3 = jtf4.getText(); str4 = jc5.getSelectedItem().toString().trim(); connectiondb c = new connectiondb(); c.addSql(str); JOptionPane.showMessageDialog(this, 添

9、加成功!); this.dispose();/关闭对话框 else if(e.getSource().equals(jb2) this.dispose(); Connectiondb类package chapter12;import java.beans.Statement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.SQLException;public class connectiondb String driverNam

10、e = com.microsoft.sqlserver.jdbc.SQLServerDriver; String dbURL = jdbc:sqlserver:/127.0.0.1:1433;DatabaseName=student; Connection dbConn; Statement stmt; PreparedStatement pstmt=null; String userName = sa; String userPwd = 123456; /返回连接数据 public Connection getdbConn() return dbConn; public connection

11、db() try Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL,userName,userPwd); catch (Exception e) System.out.println(连接失败!); e.printStackTrace(); /添加信息时,调用的方法 public void addSql(String str) String strsql = insert into st1 values(?,?,?,?,?); try pstmt = dbConn.prepareStatement(str

12、sql); for (int i = 0; i str.length; i+) pstmt.setString(i+1, stri); pstmt.executeUpdate(); catch (Exception e) e.printStackTrace(); finally /释放语句对象 连接的对象 allClose(); /删除信息时,用到的方法 public void delete(String str) try pstmt=dbConn.prepareStatement(delete from st1 where sno=?); pstmt.setString(1, str); p

13、stmt.executeUpdate(); catch (Exception e) e.printStackTrace(); finally allClose(); /查询信息时,用到的方法/ public void findSQL(String str)/ try / pstmt=dbConn.prepareStatement(select * from st1 where sname like +str+%);/ pstmt.executeUpdate();/ catch (Exception e) / e.printStackTrace();/ finally/ allClose();/

14、 / / public void findSQL1(String str)/ try / pstmt=dbConn.prepareStatement(select * from st1 where sno = +str+ );/ pstmt.executeUpdate();/ catch (Exception e) / e.printStackTrace();/ finally/ allClose();/ / /修改信息时,用到的方法 public void allClose() try if(pstmt!=null) pstmt.close(); if(dbConn!=null) dbCon

15、n.close(); catch (Exception ex) ex.printStackTrace(); public void updateIt(String str) String strsql = update st1 set sname=? ,ssex=?,birthday=?,speciality=? where sno=?; try pstmt = dbConn.prepareStatement(strsql); for (int i = 0; i str.length; i+) pstmt.setString(i+1, stri); pstmt.executeUpdate();

16、 catch (Exception e) e.printStackTrace(); finally /释放语句对象 连接的对象 allClose(); Model类package chapter12;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.ArrayList;import java.util.List;import javax.swing.table.AbstractTableModel;public class model e

17、xtends AbstractTableModel List rowData, columnNames; PreparedStatement ps = null; Connection ct = null; ResultSet rs = null; String sql ; public void way(String sql) if (sql.equals() sql = select * from st1; columnNames = new ArrayList(); columnNames.add(学号); columnNames.add(姓名); columnNames.add(性别)

18、; columnNames.add(生日); columnNames.add(专业); rowData = new ArrayList(); connectiondb c = new connectiondb(); try ct = c.getdbConn(); ps = ct.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next() / rowData可以存放多行 String s = rs.toString(); List hang = new ArrayList(); hang.add(rs.getString(1);

19、 hang.add(rs.getString(2); hang.add(rs.getString(3); hang.add(rs.getString(4); hang.add(rs.getString(5); / 加入到rowData rowData.add(hang); catch (Exception e) / TODO Auto-generated catch block e.printStackTrace(); / rowData = new ArrayList(); / rowData.add(columnNames); public model() this.way(); publ

20、ic model(String str) this.way(str); Override public int getColumnCount() / TODO Auto-generated method stub return this.columnNames.size(); Override public int getRowCount() / TODO Auto-generated method stub return this.rowData.size(); Override public Object getValueAt(int rowIndex, int columnIndex)

21、/ TODO Auto-generated method stub return (ArrayList) this.rowData.get(rowIndex).get(columnIndex); Override public String getColumnName(int arg0) / TODO Auto-generated method stub return (String) this.columnNames.get(arg0); Update类package chapter12;import java.awt.Frame;import java.awt.GridLayout;imp

22、ort java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class update extends JDialog imp

23、lements ActionListener JLabel jl1,jl2,jl3,jl4,jl5; JTextField jtf1,jtf2,jtf3,jtf4,jtf5; JButton jb1,jb2; JPanel jp1,jp2,jp3; public update(Frame owner,String title,boolean modal,model m,int rowNum) super(owner,title,modal); jp1 = new JPanel(); jl1 = new JLabel(学号); jl2 = new JLabel(姓名); jl3 = new JL

24、abel(性别); jl4 = new JLabel(出生年月); jl5 = new JLabel(专业); jp1.setLayout(new GridLayout(5,1); jp1.add(jl1); jp1.add(jl2); jp1.add(jl3); jp1.add(jl4); jp1.add(jl5); jp2 = new JPanel(); jtf1 = new JTextField(9); jtf1.setEditable(false); jtf2 = new JTextField(8); jtf3 = new JTextField(2); jtf4 = new JText

25、Field(8); jtf5 = new JTextField(10); jtf1.setText(String)m.getValueAt(rowNum, 0); jtf2.setText(String)m.getValueAt(rowNum, 1); jtf3.setText(String)m.getValueAt(rowNum, 2); jtf4.setText(String)m.getValueAt(rowNum, 3); jtf5.setText(String)m.getValueAt(rowNum, 4); jp2.setLayout(new GridLayout(5,1); jp2

26、.add(jtf1); jp2.add(jtf2); jp2.add(jtf3); jp2.add(jtf4); jp2.add(jtf5); jp3 = new JPanel(); jb1 = new JButton(修改); jb2 = new JButton(取消); jb1.addActionListener(this); jb2.addActionListener(this); jp3.add(jb1); jp3.add(jb2); this.add(jp1,Center); this.add(jp2,East); this.add(jp3,South); this.setSize(

27、200,300); this.setLocation(250, 250); this.setVisible(true); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); public void actionPerformed(ActionEvent e) if(e.getSource().equals(jb1) String str = new String5; str4 = jtf1.getText(); str0 = jtf2.getText(); str1 = jtf3.getText(); str2 = jtf4.getT

28、ext(); str3 = jtf5.getText(); connectiondb c = new connectiondb(); c.updateIt(str); JOptionPane.showMessageDialog(this, 修改成功!); this.dispose();/关闭对话框 else if(e.getSource().equals(jb2) this.dispose(); Zhujiemian类package chapter12;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1