<%@page contentType="text/html"%>
<%@page pageEncoding="gb2312"%>
<%@include file="common.jsp"%>
<%@include file="connectdb.jsp"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%!
  public String codeToString(String str)
   {
       String s=str;
       try
       {
           byte tempB[]=s.getBytes("ISO-8859-1");
           s=new String(tempB);
           return s;
       }
       catch(Exception e)
       {
           return s;
       }
   }
%>
   <%
      int dipage=1;
      String pages=request.getParameter("dipage");
      if(pages==null)
      {
          pages="1";
      }
      try{
          dipage=Integer.parseInt(pages);
      }
      catch(Exception e){
          dipage=1;
      }
%><html>
    <head>
    <%! String keyword,name,author,time,sort;%>
<%   
name= codeToString(request.getParameter("name"));
author= codeToString(request.getParameter("author"));
time= codeToString(request.getParameter("time"));
sort= codeToString(request.getParameter("sort"));
   %>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>文献检索系统</title>
        <style type="text/css">
<!--
body {
background-color: #FFFFFF;
margin-left: 100px;
margin-right: 100px;
}
.STYLE1 {color: #FF00FF}
.STYLE3 {
color: #000000;
font-size: x-large;
font-weight: bold;
font-family: "宋体";
}
-->
</style>
    </head>
    <body>
    <img src="picture/TITLE.jpg" hspace="10" />
    <form id="form1" name="form1" method="post" action="">
  <hr />
  <p>查询结果:</p>
<%    sql="select * from literaturetable where literatureName like '%+name.trim()+%' or literatureAuthor like '%+author.trim()+%' or literatureDate like '%+time.substring(0, 3).trim()+%' or className like '%+sort.trim()+%' ";
    rs=smt.executeQuery(sql);
    
    int countRecord=0;
    int countPageRecord=15;
    int countPage=0;
    rs.last();
    countRecord=rs.getRow();
    if(countRecord%countPageRecord==0)
        countPage=countRecord/countPageRecord;
    else
         countPage=countRecord/countPageRecord+1;
    if((dipage-1)*countPageRecord==0)
        rs.beforeFirst();
    else
        rs.absolute((dipage-1)*countPageRecord);
    %>
    <table border="1" cellpadding="0" cellspacing="0">
  <TR>
    <td width="600" align="center" >文&nbsp;&nbsp;献&nbsp;&nbsp;名&nbsp;&nbsp;称</td>
    <td width="100" align="center">作&nbsp;&nbsp;&nbsp;&nbsp;者</td>
    <td width="100" align="center">刊&nbsp;&nbsp;&nbsp;&nbsp;号</td>
    <td width="100" align="center">发&nbsp;&nbsp;布&nbsp;&nbsp;时&nbsp;&nbsp;间</td>
    <td width="100" align="center">所&nbsp;&nbsp;属&nbsp;&nbsp;类&nbsp;&nbsp;别</td>
 </tr>
 <TR>
    <%
       int i=0;
    while(rs.next())
    {
 %> 
 
     <td align="center"><a href="browse.jsp?id=<%=rs.getObject(1)%>" target="_blank"><%=rs.getObject(2)%></a></td>
     <td align="center"><%=rs.getObject(3)%></td>
     <td align="center"><%=rs.getObject(4)%></td>
     <td align="center"><%=rs.getObject(6)%></td>
     <td align="center"><%=rs.getObject(5)%></td>
     </TR>
<% 
   i++;
   if(i>=countPageRecord)
       break;
    }
   out.print("<tr><td colspan=4 align=right>");
   out.print("共"+countRecord+"条记录&nbsp;&nbsp;&nbsp;&nbsp;共"+countPage+"页&nbsp;&nbsp;&nbsp;&nbsp;当前第"+dipage+"页&nbsp;&nbsp;&nbsp;&nbsp;每页"+countPageRecord+"条记录&nbsp;&nbsp;&nbsp;&nbsp;");
   if(dipage==1)
       ;
   else
   { out.print("<a href=index.jsp?dipage=1>首页</a>");
      out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
       out.print("<a href=index.jsp?dipage="+(dipage-1)+">上一页</a>");
   }
   if(dipage==countPage)
       ;
   else
   { out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
      out.print("<a href=index.jsp?dipage="+(dipage+1)+">下一页</a>");
      out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
      out.print("<a href=index.jsp?dipage="+countPage+">未页</a>") ;
   }%>
</table>
  <hr /></form><table width="845" height="215" border="0" align="center" bordercolor="#FFFFFF">
  <tr align="left">
    <td width="377" height="211" align="left" valign="top">
    <form id="form2" name="form2" method="post" action="search1.jsp">
<p>综合查询:</p>
<p>&nbsp;</p>
<p>
    <label>
    <input name="radiobutton" type="radio" value="radiobutton" checked="checked" />
    请输入关键字 </label>
    <p>
    <label>
    <input name="keyword" type="text" value="" size="40" />
    </label>
</p>
        <p>
        &nbsp;
        </p>
        <p>
<input type="submit" name="Submit" value="模糊查询" />
</p>
  <p>&nbsp;</p>
    </form>    </td>
    <td width="458" valign="top">
     <form action="search2.jsp" method="post" enctype="application/x-www-form-urlencoded" name="form3" id="form3">
<p>联合查询:</p>
  <p>
    <label>
    <input type="checkbox" name="checkbox1" value="checkbox" />
    按文献名称:</label>
  
  <label>
  <input type="text" name="name" value="如:双缓冲核技术的应用" />
  </label>
  </p>
  <p>
    <label>
    <input type="checkbox" name="checkbox2" value="checkbox" />
    按作者查询:</label>
  
  <label>
  <input type="text" name="author" value="如:张三" />
  </label>
  </p>
  <p>
    <label>
    <input type="checkbox" name="checkbox3" value="checkbox" />
    按年代查询:</label>
  <label>
  <input type="text" name="time" value="如:1990,2007" />
  </label>
  </p>
  <p>
    <label>
    <input type="checkbox" name="checkbox4" value="checkbox" />
    按类别查询:</label>
    <label>
        <%
           sql="select * from classtable";
           rs=smt.executeQuery(sql);
%>
    <select name="sort" size="1" width="50">
         <option>请选择类别</option>
     <%
        while(rs.next())
        {
       %>
          <option><%=rs.getObject(2)%></option>     
   <%    }
%>
     
    </select>
    </label>
    <p>
    <input name="Submit2" type="submit"  value="精确查询" />
  </p>
  <p> 
    <label></label>
  </p>
    </form>    </td>
  </tr>
</table>
  </body>
</html>
为什么明明数据库中有.但一个也不显示.请高手指点.

解决方案 »

  1.   

    rs.last(); 
    countRecord=rs.getRow(); 
    你打印countRecord看是多少。
    rs.last(); 游标走到了最后,遍历数据当然是空的
      

  2.   

    sql="select * from literaturetable where literatureName like '%"+name.trim()+"%' or literatureAuthor like '%"+author.trim()+"%' or literatureDate like '%"+time.substring(0,3).trim()+"%' or className like '%"+sort.trim()+"%'"; 
    改成这样,看行不行!
      

  3.   

    你直接在存储过程中做多好啊!
    create proc proc_Sel
    @name varchar(10),
    @author varchar(10),
    @time varchar(10),
    @sort varhcar(10)
    as
    select   *   from   literaturetable   where   literatureName   like   '%+@name+' 
    后面一样!!
      

  4.   

    你把SQL语句打印出来,直接放到数据库中执行,看能不能查询到结果。
    如果查询得到,把程序设置一个断点,跟进去看一下吧。程序有点乱啊,
    比较难看,另外没有看到你声明ResultSet,代码不完全吧。