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

JAVA数据库课程设计--学生选课管理系统的(6)

来源:网络收集 时间:2018-12-27 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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,\还

没查找需要修改的学生/课程\ else{sql=\ try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); stmt.executeUpdate(sql); saveC=null; saveS=null; JOptionPane.showMessageDialog(this,\删除完成\ 课号.setText(\ 学号.setText(\ 成绩.setText(\ stmt.close(); }catch(SQLException e1){ System.out.print(\ } } } } }

// 连接数据库方法 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; } }

Delstu.java:

import java.awt.*;

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

public class Delstu extends JPanel implements ActionListener{ String save=null;

JTextField 学号1,学号,姓名,系别; JButton 删除,查找; public Delstu(){

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(查找);

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,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(\ 系别.setText(rs1.getString(\ save=学号1.getText().trim(); }

else{JOptionPane.showMessageDialog(this,\没有这个学号的学生\ stmt.close(); rs1.close();

}catch(SQLException e1){

System.out.print(\ } } }

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库JAVA数据库课程设计--学生选课管理系统的(6)在线全文阅读。

JAVA数据库课程设计--学生选课管理系统的(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/394971.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: