<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        
        <% String Name = request.getParameter("Name");%>
        <% String PassWord = request.getParameter("PassWord");%>
        <%
        Connection con = null;      
        Statement stmt = null;
        Statement stmt2 = null;
        //Statement stmt3 = null;
        ResultSet rs = null;
        ResultSet rs2 = null;
       // ResultSet rs3 = null;
        //String Popedom1 = "1";
        //String Popedom2 = "2";
        String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=lichao";
String username="sa"; 
String password="";  
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
        con = DriverManager.getConnection(url, username, password);
        String sql="select * from UserInfo where UserID='"+Name+"' and PassWord='"+PassWord+"'";
       // String sql2="select * from UserInfo where UserID='"+Name+"' and Pepedom='"+Popedom1+"'"; 
        //String sql3="select * from UserInfo where UserID='"+Name+"' and Pepedom='"+Popedom2+"'";
        String sql1="select Pepedom from UserInfo where UserID='"+Name+"'";
        try {
        stmt = con.createStatement();
        stmt2 = con.createStatement();
        //stmt3 = con.createStatement();
        rs = stmt.executeQuery(sql);
        rs2 = stmt2.executeQuery(sql1);
        //rs3 = stmt3.executeQuery(sql3);
        //String Popedom = rs.getString("Popedom");
         } catch (SQLException e) 
         {
                     e.printStackTrace();
         }
        if(rs.next() && rs2.getString("Popedom").equals("1"))
                {
          
          %>  
          <jsp:forward page="LoginSuccessful.jsp"/>   
          <%
          }      
        
          else if(rs.next() && rs2.getString("Popedom").equals("2"))
          {
          %>
          <jsp:forward page="WorkerLoginSuccessfull.jsp"/>
          <%
          }
          else
          {           
          %>
          <jsp:forward page="LoginFail.jsp"/>
          <%
          }
          
          
          %>
       
    </body>
</html>

解决方案 »

  1.   

    应该是这里的问题if(rs.next() && rs2.getString("Popedom").equals("1"))else if(rs.next() && rs2.getString("Popedom").equals("2"))rs next() 但rs2没有next
      

  2.   

    解决了 o打成e了。。呵呵 
    又有个错误Invalid operation for the current cursor position. 为什么啊
      

  3.   

    据我所知,在一个页面同时操作多个Statement好像不行,要是你想同时用两个Statement的话可以采取以下两种方法:
    方法一:在数据库驱动中这么写
    String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=lichao;SelectMethod=Cursor;"
    方法二: 当第一个Statement用完时在用它来执行下一个sql
      

  4.   


        if(rs.next())
        {
                while(rs2.next())
                    {                          
                              
        %> 
        <jsp:forward page="LoginSuccessful.jsp"/> 
        <%
                }
                while(rs3.next())
                    {             
                     %>
        <jsp:forward page="WorkerLoginSuccessfull.jsp"/>
        <%
                    }
         
       }
        else
            {
        %>
        <jsp:forward page="LoginFail.jsp"/>
        <%
       }
        %>
    这样 可以 谢谢大家