登录 注册
当前位置:主页 > 资源下载 > 43 > 学生管理系统采用Java开发,并与Mysql数据库相结合,同时具备图形用户界面(GUI)

学生管理系统采用Java开发,并与Mysql数据库相结合,同时具备图形用户界面(GUI)

  • 更新:2024-12-14 16:24:32
  • 大小:29KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:其它 - 开发技术
  • 格式:RAR

资源介绍

录入=new JButton("录入"); 查询=new JButton("查询");删除=new JButton("删除"); 修改=new JButton("修改");显示=new JButton("显示");录入.addActionListener(new InputAct());查询.addActionListener(new InquestAct()); 修改.addActionListener(new ModifyAct());删除.addActionListener(new DeleteAct());显示.addActionListener(new ShowAct()); 修改.setEnabled(false); p1=new JPanel(); p1.add(new JLabel("学号:",JLabel.CENTER)); p1.add(学号); p2=new JPanel(); p2.add(new JLabel("姓名:",JLabel.CENTER)); p2.add(姓名); p3=new JPanel(); p3.add(new JLabel("性别:",JLabel.CENTER)); p3.add(男); p3.add(女); p4=new JPanel(); p4.add(new JLabel("专业:",JLabel.CENTER)); p4.add(专业); p5=new JPanel(); p5.add(new JLabel("年级:",JLabel.CENTER)); p5.add(年级); p6=new JPanel(); p6.add(new JLabel("出生:",JLabel.CENTER)); p6.add(出生); pv=new JPanel(); pv.setLayout(new GridLayout(6,1)); pv.add(p1); pv.add(p2); pv.add(p3); pv.add(p4); pv.add(p5); pv.add(p6); ph=new JPanel(); ph.add(录入); ph.add(查询); ph.add(修改); ph.add(删除); ph.add(显示); file=new File("学生信息.txt"); 学生散列表=new Hashtable(); if(!file.exists()){ try{ FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(学生散列表); objectOut.close(); out.close(); } catch(IOException e){} } Container con=getContentPane(); con.setLayout(new BorderLayout()); con.add(lb, BorderLayout.WEST); con.add(pv, BorderLayout.CENTER); con.add(ph, BorderLayout.SOUTH); setDefaultCloseOperation(EXIT_ON_CLOSE); setBounds(100,100,600,300); setVisible(true); Statement stmt; ResultSet rs; } public static void main(String[] args) {StudentManager ff=new StudentManager();} //添加学生信息,的Mysql操作 public class InputAct implements ActionListener{ public void actionPerformed(ActionEvent e){ 修改.setEnabled(false); String number=""; number=学号.getText(); if(number.length()>0){ if(学生散列表.containsKey(number)){ String warning="该生信息已存在,请到修改页面修改!"; JOptionPane.showMessageDialog(null,warning,"警告", JOptionPane.WARNING_MESSAGE); }//end if1 else{ String m="该生信息将被录入!"; int ok=JOptionPane.showConfirmDialog(null,m,"确认", JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE); if(ok==JOptionPane.YES_OPTION) { try { Class.forName("org.gjt.mm.mysql.Driver"); } catch(java.lang.ClassNotFoundException e11) { System.out.println("Class not found exception occir.Message is:"); System.out.println(e11.getMessage()); } try { PreparedStatement prepstmt1; Statement stmt; ResultSet rs; String url = "jdbc:mysql://localhost/test?user=root&password=0&useUnicode=true&&characterEncoding=8859_1"; String user="root"; String password="0"; Connection conn=null; try { conn=DriverManager.getConnection(url,user,password); } catch(Exception ex) { ex.printStackTrace(); } //对制定的数据库添加信息 String sql1="INSERT INTO students(student_id,name,sex,job,data,grade)"+"VALUES(?,?,?,?,?,?)"; prepstmt1=(PreparedStatement)conn.prepareStatement(sql1); prepstmt1.setString(1,学号.getText()); prepstmt1.setString(2,姓名.getText()); if(男.isSelected()){prepstmt1.setString(3,"男.getText()");} else{prepstmt1.setString(3,女.getText());} prepstmt1.setString(4,专业.getText()); prepstmt1.setString(5,年级.getText()); prepstmt1.setString(6,出生.getText()); prepstmt1.executeUpdate(); } catch(SQLException e1) { System.out.println("SQL Exception occur.Message is:"); System.out.println(e1.getMessage()); } } else{ String warning="必须输入学号!"; JOptionPane.showMessageDialog(null,warning, "警告",JOptionPane.WARNING_MESSAGE); }//end else0 } } else{ String warning="必须输入学号!"; JOptionPane.showMessageDialog(null,warning, "警告",JOptionPane.WARNING_MESSAGE); } } }