java程序谁给运行一 并告诉我怎样才能成功
try{    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");   con=DriverManager.getConnection("jdbc:odbc:PIMS", "Test", "000123");stmt=con.createStatement();if(choice.getSelectedItem().equals("学生"))    {       boolean tag=false;       rs=stmt.executeQuery("select * From 学生基本信息");       while(rs.next())       {          if(rs.getInt("密码")==Int1 && rs.getString("学号").equals(ID))          {            getJFrame2().setVisible(true);            setVisible(false);            tag=true;            break;         }         if(jTextField.getText().equals(""))         {              JOptionPane.showMessageDialog(null, "用户名不能为空");              jPasswordField.setText(null);              tag=true;              break;         }    }if(tag==false){       JOptionPane.showMessageDialog(null, "用户名或密码错误");       jPasswordField.setText(null);    }}else if(choice.getSelectedItem().equals("教师")){       boolean tag=false;       rs=stmt.executeQuery("select * From 教师基本信息");       while(rs.next())       {           if(rs.getInt("密码")==Int1 && rs.getString("教工号").equals(ID))           {               getJFrame3().setVisible(true);               jPanel1.setVisible(false);               setVisible(false);               tag=true;               break;            }           if(jTextField.getText().equals(""))           {              JOptionPane.showMessageDialog(null, "用户名不能为空");              jPasswordField.setText(null);              tag=true;              break;            }        }        if(tag==false)        {              JOptionPane.showMessageDialog(null, "用户名或密码错误");              jPasswordField.setText(null);        }     }     stmt.close();     con.close();    }    catch(Exception ex){        JOptionPane.showMessageDialog(null, "请注册用户");    }

解决方案 »

  1.   


    try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con=DriverManager.getConnection("jdbc:odbc:PIMS", "Test", "000123");
      stmt=con.createStatement();
      if(choice.getSelectedItem().equals("学生")){
      boolean tag=false;
      rs=stmt.executeQuery("select * From 学生基本信息");
      while(rs.next()){
      if(rs.getInt("密码")==Int1 && rs.getString("学号").equals(ID)){
      getJFrame2().setVisible(true);
      setVisible(false);
      tag=true;
      break;
      }
      if(jTextField.getText().equals(""))
      {
      JOptionPane.showMessageDialog(null, "用户名不能为空");
      jPasswordField.setText(null);
      tag=true;
      break;
      }
      }
      if(tag==false){
      JOptionPane.showMessageDialog(null, "用户名或密码错误");
      jPasswordField.setText(null);
      }
      }else if(choice.getSelectedItem().equals("教师")){
       boolean tag=false;
       rs=stmt.executeQuery("select * From 教师基本信息");
       while(rs.next()){
       if(rs.getInt("密码")==Int1 && rs.getString("教工号").equals(ID)){
       getJFrame3().setVisible(true);
       jPanel1.setVisible(false);
       setVisible(false);
       tag=true;
       break;
       }
       if(jTextField.getText().equals("")){
       JOptionPane.showMessageDialog(null, "用户名不能为空");
       jPasswordField.setText(null);
       tag=true;
       break;
       }
       }
       if(tag==false){
       JOptionPane.showMessageDialog(null, "用户名或密码错误");
       jPasswordField.setText(null);
       }
       }
      stmt.close();
      con.close();
    }
    catch(Exception ex){
    JOptionPane.showMessageDialog(null, "请注册用户");
    }
      

  2.   

    整理了一下,很多东西不知道做什么的,
    choice.getSelectedItem()是什么?这个可以获取到值吗?
    Int1,ID都是什么?jTextField.getText().equals("")这句最好改成 "".equals(jTextField.getText());
      

  3.   

    if(rs.getInt("密码")==Int1 && rs.getString("学号").equals(ID))
    Int1,ID从哪里来的?jTextField.getText().equals("")如果这里是获取用户名,那么是否在sql检索里加上条件比较好,不用全检索再比较吧String username = jTextField.getText();
    if (username == null || "".equals(username.trim())) {
        JOptionPane.showMessageDialog(null, "用户名不能为空");
        jPasswordField.setText(null);
        return;
    }
    boolean tag=false;
    if(choice.getSelectedItem().equals("学生")){
        rs=stmt.executeQuery("select * From 学生基本信息 where username = '"
                             + username + "'");
        while(rs.next()){
            if(rs.getInt("密码")==Int1 && rs.getString("学号").equals(ID)){
                getJFrame2().setVisible(true);
                setVisible(false);
                tag=true;
                break;
            }
        }} else if (choice.getSelectedItem().equals("教师")) {
        rs=stmt.executeQuery("select * From 教师基本信息 where username = '"
                             + username + "'");
        while(rs.next()){
            if(rs.getInt("密码")==Int1 && rs.getString("教工号").equals(ID)){
                getJFrame3().setVisible(true);
                jPanel1.setVisible(false);
                setVisible(false);
                tag=true;
                break;
            }
        }
    }
    if(tag==false){
        JOptionPane.showMessageDialog(null, "用户名或密码错误");
        jPasswordField.setText(null);
    }
      

  4.   

    我回来了,多谢podongxi777442156445的整理,查看
    qybao的指明,
    部分参数的确来源不明,类型不清楚