第一范文网 - 专业文章范例文档资料分享平台

java学生选课系统(完整源代码,sql2005)

来源:用户分享 时间:2025/6/13 5:21:17 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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(\

stmt.close(); }catch(SQLException e1){ 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; } }

DelSC.java:

import java.awt.*;

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

public class DelSC extends JPanel implements ActionListener{ String saveC=null;

String saveS=null; JTextField 课号1,学号1,学号,课号,成绩; JButton 删除,查找;

public DelSC(){ try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch(Exception e){System.err.println(\不能设置外观: \ 学号1=new JTextField(12); 课号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(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 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; if(obj==查找){if(课号1.getText().equals(\学号1.getText().equals(\请填写完成查询的信息!\ else{ sql1=\* from SC where Cno='\课号1.getText()+\and Sno='\学号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(\ saveC=课号1.getText().trim(); saveS=学号1.getText().trim(); } else{JOptionPane.showMessageDialog(this,\没有这个课号的学生\ stmt.close(); rs1.close(); }catch(SQLException e1){ System.out.print(\ } } } else{ if(obj==删除){if(saveC==null||saveS==null)JOptionPane.showMessageDialog(this,\还

java学生选课系统(完整源代码,sql2005).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1qwqa0r29d77xpo57x03_7.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top