⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deletefamily.java

📁 学生档案管理系统
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package 学生档案管理系统;/** * * @author Administrator */import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;public class DeleteFamily extends JDialog{    Statement ps;    ResultSet rs;    Connection con;    String url;        String strName;    String strRelation;    String strPhoneNum;    String strJobAddress;        JPanel panel = new JPanel();         JPanel panelb = new JPanel();    JLabel labName = new JLabel();    JTextField txtName = new JTextField();    JLabel labRelation = new JLabel();    JTextField txtRelation = new JTextField();    JLabel labPhoneNum = new JLabel();    JTextField txtPhoneNum = new JTextField();    JLabel labJobAddress = new JLabel();    JTextField txtJobAddress = new JTextField();        JButton sure = new JButton();    JButton cancel = new JButton();            public DeleteFamily(Frame frame, String title, boolean modal) {        super(frame, title, modal);        try {            jbInit();            pack();        }        catch (Exception ex) {            ex.printStackTrace();        }    }        public DeleteFamily() {        this(null, "", true);    }    private void jbInit() throws Exception{try {                try {                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                    Connection con = DriverManager.getConnection("jdbc:odbc:学生档案","", "");                    ps = con.createStatement();                }                catch (Exception err) {                    String error = err.getMessage();                    JOptionPane.showMessageDialog(null, "连接数据库错误!");                }                try {                    String strSNum = "'"+MainFrame.strSNum+"'";                    String sqlStr = "Select * from 家庭成员表 where 学号 ="+ strSNum;                    rs = ps.executeQuery(sqlStr);                      while(rs.next()){                        strName = rs.getString(3);                                                strRelation = rs.getString(4);                        strPhoneNum = rs.getString(5);                        strJobAddress = rs.getString(6);                    }                    ps.close();                }                catch (SQLException sqle) {                    String error = sqle.getMessage();                    JOptionPane.showMessageDialog(null, error);                    sqle.printStackTrace();                }            }            catch (Exception ex) {                ex.getMessage();                String error = ex.getMessage();                JOptionPane.showMessageDialog(null, error);                ex.printStackTrace();            }                labName.setText("姓      名 ");        txtName.setEditable(false);        txtName.setText(strName);        labRelation.setText("与本人关系");        txtRelation.setEditable(false);        txtRelation.setText(strRelation);        labPhoneNum.setText("联系电话");        txtPhoneNum.setEditable(false);        txtPhoneNum.setText(strPhoneNum);        labJobAddress.setText("所在单位");        txtJobAddress.setEditable(false);        txtJobAddress.setText(strJobAddress);                sure.setText("确定");        sure.addActionListener(new deleteFamily_sure_actionAdapter(this));        cancel.setText("取消");        cancel.addActionListener(new deleteFamily_cancel_actionAdapter(this));                panel.setBorder(BorderFactory.createLoweredBevelBorder());        panel.setLayout(new GridBagLayout());                LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,0,0,1,1,labName);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,1,0,1,1,txtName);        LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,2,0,1,1,labRelation);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,3,0,1,1,txtRelation);                LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,0,1,1,1,labPhoneNum);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,1,1,1,1,txtPhoneNum);        LayoutUtil.add(panel,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,2,1,1,1,labJobAddress);        LayoutUtil.add(panel,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,1,0,3,1,1,1,txtJobAddress);                panelb.setLayout(new GridBagLayout());        LayoutUtil.add(panelb,GridBagConstraints.NONE,GridBagConstraints.CENTER,0,0,0,0,1,1,sure);        LayoutUtil.add(panelb,GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0,0,1,0,1,1,cancel);                this.getContentPane().add(panel,BorderLayout.CENTER);        this.getContentPane().add(panelb,BorderLayout.SOUTH);        this.setBounds(100, 100, 400, 300);        this.setVisible(true);    }void cancel_actionPerformed(ActionEvent e) {        this.dispose();    }    void sure_actionPerformed(ActionEvent e) {            JOptionPane.showConfirmDialog(null,"确定删除?", "删除家庭成员信息", JOptionPane.YES_NO_OPTION);            try {                try {                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                    Connection con = DriverManager.getConnection("jdbc:odbc:学生档案","", "");                    ps = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);                }                catch (Exception err) {                    String error = err.getMessage();                    JOptionPane.showMessageDialog(null, "连接数据库错误!");                }                try {                                       String strSNum = "'"+MainFrame.strSNum+"'";                                        String sqlStr = "Delete from 家庭成员表 where 学号 = " + strSNum;                    ps.execute(sqlStr);                                        ps.close();                                       JOptionPane.showMessageDialog(null, "删除成功");                    this.dispose();                }                catch (SQLException sqle) {                    String error = sqle.getMessage();                    JOptionPane.showMessageDialog(null, error);                    sqle.printStackTrace();                }            }            catch (Exception ex) {                ex.getMessage();                String error = ex.getMessage();                JOptionPane.showMessageDialog(null, error);                ex.printStackTrace();            }        }    }//}class deleteFamily_cancel_actionAdapter    implements java.awt.event.ActionListener {    DeleteFamily adaptee;    deleteFamily_cancel_actionAdapter(DeleteFamily adaptee) {        this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {        adaptee.cancel_actionPerformed(e);    }}class deleteFamily_sure_actionAdapter    implements java.awt.event.ActionListener {    DeleteFamily adaptee;    deleteFamily_sure_actionAdapter(DeleteFamily adaptee) {        this.adaptee = adaptee;    }    public void actionPerformed(ActionEvent e) {        adaptee.sure_actionPerformed(e);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -