当前位置:首页 > JAVA数据库课程设计--学生选课管理系统的分解
box3.add(系别); box4.add(录入); Box boxH=Box.createVerticalBox();//竖放box boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(Box.createVerticalGlue()); JPanel messPanel=new JPanel(); messPanel.add(boxH); setLayout(new BorderLayout()); add(messPanel,BorderLayout.CENTER); validate(); }
public void actionPerformed(ActionEvent c){ Object obj=c.getSource(); if(obj==录入){ if(学号.getText().equals(\姓名.getText().equals(\系别.getText().equals(\ JOptionPane.showMessageDialog(this,\学生信息请填满再录入!\ } Statement stmt=null; ResultSet rs1=null; String sql,sql1; sql1=\学号.getText()+\ sql=\into S values('\学号.getText()+\姓名.getText()+\系别.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{ stmt.executeUpdate(sql); JOptionPane.showMessageDialog(this,\添加成功\ } rs1.close(); stmt.close(); } catch(SQLException e){
System.out.print(\Exception occur.Message is:\ } } }
//连接数据库方法
public static Connection CONN(){ String driverName = \ //加载JDBC驱动 String dbURL = \DatabaseName=student\ //连接服务器和数据库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) { e.printStackTrace(); } return dbConn; } }
DelC.java:
import java.awt.*;
import java.awt.event.*; import java.sql.*; import javax.swing.*;
public class DelC extends JPanel implements ActionListener{ String save=null; JTextField 课号1,课号,课名; JButton 删除,查找; public DelC(){ try
{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
catch(Exception e){System.err.println(\不能设置外观: \ 课号1=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(课名); box4.add(删除); box5.add(new JLabel(\课号:\ box5.add(课号1); box5.add(查找); Box boxH=Box.createVerticalBox();//竖放box boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(Box.createVerticalGlue()); 删除.addActionListener(this); 查找.addActionListener(this); JPanel picPanel=new JPanel(); JPanel messPanel=new JPanel(); messPanel.add(box5); picPanel.add(boxH); setLayout(new BorderLayout()); JSplitPane JSplitPane(JSplitPane.VERTICAL_SPLIT,messPanel,picPanel);//分割 add(splitV,BorderLayout.CENTER); validate(); }
public void actionPerformed(ActionEvent e){ Object obj=e.getSource();
splitV=new Statement stmt=null; ResultSet rs=null,rs1=null; String sql=null,sql1=null,sqlSC=null; 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(\ save=课号1.getText().trim(); } else{JOptionPane.showMessageDialog(this,\没有这个课号的课程\ stmt.close(); rs1.close(); }catch(SQLException e1){ System.out.print(\Exception occur.Message is:\ } } } else{ if(obj==删除){if(save==null)JOptionPane.showMessageDialog(this,\还没查找需要修改的课程\ else{sql=\ sqlSC=\ try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); stmt.executeUpdate(sql); stmt.executeUpdate(sqlSC); save=null; JOptionPane.showMessageDialog(this,\删除完成\ 课号.setText(\ 课名.setText(\
共分享92篇相关文档