JAVA数据库课程设计--学生选课管理系统的设计与实现_完整源代码_

发布时间 : 星期二 文章JAVA数据库课程设计--学生选课管理系统的设计与实现_完整源代码_更新完毕开始阅读

String userPwd = \ //密码 Connection dbConn=null; try { Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL, userName, userPwd); System.out.println(\Successful!\ //如果连接成功 控制台输出Connection Successful! } catch (Exception e) { e.printStackTrace(); } return dbConn; } }

Updatastu.java:

import java.awt.*;

import java.awt.event.*; import java.sql.*; import javax.swing.*;

public class Updatastu extends JPanel implements ActionListener{ String save=null; JTextField 学号1,学号,姓名,系别; JButton 修改,查找;

public Updatastu(){ try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch(Exception e){System.err.println(\不能设置外观: \ 学号1=new JTextField(12); 学号=new JTextField(12); 姓名=new JTextField(12); 系别=new JTextField(12); 修改=new JButton(\修改\ 查找=new JButton(\查找\ Box box1=Box.createHorizontalBox();//横放box Box box2=Box.createHorizontalBox(); Box box3=Box.createHorizontalBox(); Box box4=Box.createHorizontalBox(); Box box5=Box.createHorizontalBox();

box1.add(new JLabel(\学号:\ box1.add(学号); box2.add(new JLabel(\姓名:\ box2.add(姓名); box3.add(new JLabel(\系别:\ box3.add(系别); box4.add(修改); box5.add(new JLabel(\学号:\ box5.add(学号1); box5.add(查找); 修改.addActionListener(this); 查找.addActionListener(this); Box boxH=Box.createVerticalBox();//竖放box boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(Box.createVerticalGlue()); JPanel picPanel=new JPanel(); JPanel messPanel=new JPanel(); messPanel.add(box5); picPanel.add(boxH); setLayout(new BorderLayout()); JSplitPane splitV=new JSplitPane(JSplitPane.VERTICAL_SPLIT,messPanel,picPanel);//分割 add(splitV,BorderLayout.CENTER); validate(); }

public void actionPerformed(ActionEvent e){ Object obj=e.getSource(); Statement stmt=null; ResultSet rs=null,rs1=null; String sql=null,sql1=null,sqlSC; if(obj==查找){if(学号1.getText().equals(\请填写查询的学号!\ else{ sql1=\学号1.getText()+\ try{ Connection dbConn1=CONN();

stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs1=stmt.executeQuery(sql1); if(rs1.next()){学号.setText(rs1.getString(\ 姓名.setText(rs1.getString(\ 系别.setText(rs1.getString(\ save=学号1.getText(); } else{JOptionPane.showMessageDialog(this,\没有这个学号的学生\ stmt.close(); rs1.close(); }catch(SQLException e1){ System.out.print(\ } } } else{ if(obj==修改){if(save==null){JOptionPane.showMessageDialog(this,\还没查找需要修改的学生\ else{ if(学号.getText().equals(\姓名.getText().equals(\系别.getText().equals(\ JOptionPane.showMessageDialog(this,\学生信息填满才能修改!\ } else{sql=\学号.getText()+\姓名.getText()+\系别.getText()+\ if(save.trim().equals(学号.getText().trim())){ try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); stmt.executeUpdate(sql); save=null; JOptionPane.showMessageDialog(this,\修改完成\ 学号.setText(\ 姓名.setText(\ 系别.setText(\ stmt.close(); }catch(SQLException e1){ System.out.print(\ } } else{sql1=\学号.getText()+\

try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs1=stmt.executeQuery(sql1); if(rs1.next()){ JOptionPane.showMessageDialog(this,\已存在此学号学生\ } else{ sqlSC=\学号.getText()+\ stmt.executeUpdate(sql); stmt.executeUpdate(sqlSC); save=null; JOptionPane.showMessageDialog(null,\修改完成\ 学号.setText(\ 姓名.setText(\ 系别.setText(\ stmt.close(); rs1.close(); }catch(SQLException e1){ System.out.print(\ } } }}}} }

//连接数据库方法

public static Connection CONN(){ String driverName = \ //加载JDBC驱动 String dbURL = \ //连接服务器和数据库test String userName = \ //默认用户名 String userPwd = \ //密码 Connection dbConn=null; try { Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL, userName, userPwd); System.out.println(\Successful!\ //如果连接成功 控制台输出Connection Successful! } catch (Exception e) {

联系合同范文客服:xxxxx#qq.com(#替换为@)