日期:2014-05-17  浏览次数:20861 次

if(rs.next())报错
<%
  javaDB db=new javaDB();
  request.setCharacterEncoding("GB2312");
  String name = request.getParameter("userName");
  String password = request.getParameter("password");
  String sql="select * from Login WHERE username='"+name+"' && pwd='"+password+"'";
  ResultSet rs=db.executeQuery(sql);
   
  if(!rs.next()) 
  {%>
  <script type="text/javascript">
  alert("用户名和密码不正确!!!");
  //window.location.href='login.jsp';
  </script>
  <% 
  }
  else {
  response.sendRedirect("afterLogin.jsp");
  }
  %>
 
</body>
</html> 
服务器遇到内部错误,无法满足这个访问请求

异 常 

org.apache.jasper.JasperException: Exception in JSP: /judge.jsp:21

18: String sql="select * from Login WHERE username='"+name+"' && pwd='"+password+"'";
19: ResultSet rs=db.executeQuery(sql);
20:  
21: if(!rs.next()) 
22: {%>
23: <script type="text/javascript">
24: alert("用户名和密码不正确!!!");


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:395)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


起 因 



------解决方案--------------------
探讨
javaDB 这个类的代码贴出来看看
ResultSet rs=db.executeQuery(sql);这个里面rs可能为null
另外在mysql中是可以使用&amp;&amp; 和 || , 等同于and 和 or;但是在oracle中则不行