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

📄 20041158133492905.java

📁 用JAVA做的一个学生管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                  {
                   //rs = st.executeQuery("select * from Coolboy where id ='2004010123'");
                      rs = st.executeQuery(strSQL);
                      int count = 0;
                      while(rs.next())
                       {
                             id = rs.getString("id");
                             name = rs.getString("name");
                             department = rs.getString("department");
                             sex = rs.getString("sex");
                             birthday = rs.getString("birthday");
                             nation = rs.getString("nation");
                             ++count;
                        }
                       if(count==0)
                             JOptionPane.showMessageDialog(null,"对不起,没有您要查找的学生!");
                       else
                       {
                             idT.setText(id);
                             nameT.setText(name);
                             sexT.setText(sex);
                             birthdayT.setText(birthday);
                             nationT.setText(nation);
                             departmentT.setText(department);
                        }
                    }
                    catch(Exception ex)
                    {
                         JOptionPane.showMessageDialog(null,"抱歉,程序出现异常!");
                    }

             }
        }
////////////////////////////////////////////////////////////////////////////////////
        if(e.getSource()==subMenu1[4])
        {
           closeDB();
           System.exit(0);
        }
/////////////////////////////////////////////////////////////////////////////////////
        if(e.getSource()==subMenu2[1] || e.getSource()==toolBarButton[1])
        {
             JOptionPane.showMessageDialog(null,"请输入要添加的学生信息");
             idT.setEnabled(true);
             idT.setText("");
             nameT.setText("");
             sexT.setText("");
             birthdayT.setText("");
             nationT.setText("");
             departmentT.setText("");

         }
//////////////////////////////////////////////////////////////////////////////////////
         if(e.getSource()==toolBarButton[5] || e.getSource()==subMenu2[5])
         {
            if((idT.getText().trim()).equals("") || (nameT.getText().trim()).equals("") || (sexT.getText().trim()).equals("") || (birthdayT.getText().trim()).equals("") ||(nationT.getText().trim()).equals("") || (departmentT.getText().trim()).equals(""))
            JOptionPane.showMessageDialog(null,"请输入信息再点击提交添加!");
            else
           {
                id = idT.getText();
                name = nameT.getText();
                sex = sexT.getText();
                birthday = birthdayT.getText();
                nation = nationT.getText();
                department = departmentT.getText();
                String strSQL ="insert into Coolboy(id,name,sex,birthday,nation,department) values('" + id + "','" + name + "','" + sex + "','" + birthday + "','" + nation + "','" + department + "')";
           try
           {
                st.executeUpdate(strSQL);
            }
           catch(Exception exx)
           {
                JOptionPane.showMessageDialog(null,"数据库中已经存在您要添加的学生的学号!");
                /*idT.setText("");
                  nameT.setText("");
                  sexT.setText("");
                  birthdayT.setText("");
                  nationT.setText("");
                  departmentT.setText("");*/
                  return;
           }
           JOptionPane.showMessageDialog(null,"恭喜您,添加成功了!");
       }
    }
////////////////////////////////////////////////////////////////////////////////////////////
    if(e.getSource()==subMenu2[4] || e.getSource()==toolBarButton[4])
    {
        if((idT.getText().trim()).equals("") || (nameT.getText().trim()).equals("") || (sexT.getText().trim()).equals("") || (birthdayT.getText().trim()).equals("") ||(nationT.getText().trim()).equals("") || (departmentT.getText().trim()).equals(""))
        {
             JOptionPane.showMessageDialog(null,"请输入信息再点击修改!");
             return;
        }
        else
        {
        id = idT.getText();
        name = nameT.getText();
        sex = sexT.getText();
        birthday = birthdayT.getText();
        nation = nationT.getText();
        department = departmentT.getText();
        String strSQL ="update Coolboy set name='"+name+"',sex='"+sex+"',birthday='"+birthday+"',nation='"+nation+"',department='"+department+"'"+"where id='"+id+"'";
        try
        {
           st.executeUpdate(strSQL);
        }
        catch(Exception exx)
        {
             JOptionPane.showMessageDialog(null,"数据库中已经存在您要修改的学生记录!");
             /*idT.setText("");
               nameT.setText("");
               sexT.setText("");
               birthdayT.setText("");
               nationT.setText("");
              departmentT.setText("");*/
              return;
         }
     JOptionPane.showMessageDialog(null,"恭喜您,修改成功了!");
    }

  }
//////////////////////////////////////////////////////////////////////////////////////////
   if(e.getSource()==subMenu2[3]||e.getSource()==toolBarButton[3])
   {
       String idid = JOptionPane.showInputDialog("请输入要修改的学生学号");
       if(idid.trim()!="")
       {
          String strSQL = "select * from Coolboy where id ='" + idid + "'";
          try
          {
               //rs = st.executeQuery("select * from Coolboy where id ='2004010123'");
                rs = st.executeQuery(strSQL);
                int count = 0;
                while(rs.next())
                  {
                       id = rs.getString("id");
                       name = rs.getString("name");
                       department = rs.getString("department");
                       sex = rs.getString("sex");
                       birthday = rs.getString("birthday");
                       nation = rs.getString("nation");
                       ++count;
                    }
                 if(count==0)
                    JOptionPane.showMessageDialog(null,"对不起,没有您要修改的学生信息!");
                 else
                 {
                      idT.setText(id);
                      nameT.setText(name);
                      sexT.setText(sex);
                      birthdayT.setText(birthday);
                      nationT.setText(nation);
                      departmentT.setText(department);
                      idT.setEnabled(false);
                  }
              }
              catch(Exception ex)
              {
                   JOptionPane.showMessageDialog(null,"抱歉,程序出现异常!");
              }

           }
        }
//////////////////////////////////////////////////////////////////////////////////////////////
        if(e.getSource()==subMenu2[2]||e.getSource()==toolBarButton[2])
        {
           String idDel = JOptionPane.showInputDialog("请输入要删除的学生学号");
            if(idDel.trim()!="")
           {
                  String strSQL = "select * from Coolboy where id ='" + idDel + "'";
                  try
                  {

                     rs = st.executeQuery(strSQL);
                     int count = 0;
                     while(rs.next())
                     {
                         id = rs.getString("id");
                         name = rs.getString("name");
                         department = rs.getString("department");
                         sex = rs.getString("sex");
                         birthday = rs.getString("birthday");
                         nation = rs.getString("nation");
                         ++count;
                      }
                      if(count==0)
                         JOptionPane.showMessageDialog(null,"对不起,没有您要删除的学生信息!");
                      else
                      {
                         idT.setText(id);
                         nameT.setText(name);
                         sexT.setText(sex);
                         birthdayT.setText(birthday);
                         nationT.setText(nation);
                         departmentT.setText(department);
                         idT.setEnabled(false);
                       }
                  }
                  catch(Exception ex)
                    {
                        JOptionPane.showMessageDialog(null,"抱歉,程序出现异常!");
                    }

                }
            }
//////////////////////////////////////////////////////////////////////////////////////////////
            if(e.getSource()==toolBarButton[6] || e.getSource()==subMenu2[6])
            {
                if((idT.getText().trim()).equals("") || (nameT.getText().trim()).equals("") || (sexT.getText().trim()).equals("") || (birthdayT.getText().trim()).equals("") ||(nationT.getText().trim()).equals("") || (departmentT.getText().trim()).equals(""))
                {
                   JOptionPane.showMessageDialog(null,"请点击删除记录按钮!");
                   return;
                }
                else
                {
                 id = idT.getText();
               //idT.setEnabled(false);
               /*name = nameT.getText();
                sex = sexT.getText();
                birthday = birthdayT.getText();
                nation = nationT.getText();
                department = departmentT.getText();*/
                String strSQL ="delete from Coolboy where id='"+id+"'";
                try
                {
                  st.executeUpdate(strSQL);
                }
                catch(Exception exx)
                {
                JOptionPane.showMessageDialog(null,"华瑞工作室通知您:出错了!");
                     /*idT.setText("");
                     nameT.setText("");
                     sexT.setText("");
                     birthdayT.setText("");
                     nationT.setText("");
                     departmentT.setText("");*/
                     return;
                }
                JOptionPane.showMessageDialog(null,"删除成功!");
             }
        }

///////////////////////////////////////////////////////////////////////////////////////////


    }


}

⌨️ 快捷键说明

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