当前位置: 代码迷 >> J2SE >> 结果显示No row count was produced,求。
  详细解决方案

结果显示No row count was produced,求。

热度:104   发布时间:2016-04-24 02:04:02.0
结果显示No row count was produced,求高手指点。。。
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*" %>
<html>
<head><title>用户登录</title>
</head>
<body><center>
<% request.setCharacterEncoding("utf-8");
  String s_username=request.getParameter("username");
  if(s_username==null){
  s_username="";
  }
  String s_password=request.getParameter("password");
  if(s_password==null){
  s_password="";
  }
%>
<font size=4 color=blue>用户登陆</font><hr>
<% 
  String sql;
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
  Connection conn=DriverManager.getConnection("jdbc:odbc:myselflk","sa","");  
  Statement stmt=conn.createStatement();  
  try{
  sql="select username from web1.dbo.myself where password='"+s_password+"'";

stmt.executeUpdate(sql);
  ResultSet rs; //建立ResultSet(结果集)对象
  rs=stmt.executeQuery("select username from web1.dbo.myself where password='"+s_password+"'");
  //执行SQL语句
%>
<table border=3>
  <tr bgcolor=silver><b>
  <td><center>您好!</td><td><center>用户名</td><td><center>登陆成功!</td>
  </tr>
<% 
  //利用while循环将数据表中的记录列出

  while (rs.next()){
%>
  <tr>
 <td width="165"><a class="navText"><center>欢迎光临!</a></td>
  <td><font size=2><%= rs.getString("username") %></font></td>
  <td width="165"><a href="main.html" class="navText"><center>进入主页>></a></td>
  </tr> 
<%
  }

  rs.close(); //关闭ResultSet对象
 }
  catch(Exception e){
  out.println(e.getMessage());
  }
  stmt.close(); //关闭Statement对象
  conn.close(); //关闭Connection对象
%>
</table></center>
<p></p><p></p>
<tr>
  <td width="165"><a href="enter.html" class="navText"><center><<重新登录</a></td>
</tr>
</body></html>

------解决方案--------------------
Java code
String sql;                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                Connection conn = DriverManager.getConnection("jdbc:odbc:myselflk",                        "sa", "");                Statement stmt = conn.createStatement();                try {                    sql = "select * from web1.dbo.myself where username='"                            + s_username + "'";                    ResultSet rs = stmt.executeQuery(sql);                    if(!rs.next()){                    %>                    <div>用户不存在</div>                                        <%                     }                    rs = stmt                            .executeQuery("select username from web1.dbo.myself where password='"                                    + s_password + "'");                    //执行SQL语句            %>
------解决方案--------------------
你的代码中没有用户名的判断。。。。
  相关解决方案