Statement st=null;
把你的Statement声明放到try块外面。
像你那样声明只能在try块里面可见

解决方案 »

  1.   

    同上,这就是jsp的弊端,这种错误都检查不出来,如果是javabean,IDE都会提示错误的
      

  2.   

    <% 
      String   driverClass   =   "com.microsoft.jdbc.sqlserver.SQLServerDriver";   
      String   connectUrl   =   "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=words"; 
      Connection conn=null;
      Statement st=null;
    ResultSet rsn=null;
      int searchnum=0;
      String keyword="";
      String way="";
      String strSQL="";
      String sqln="";
      String properties="";
      String word="";
      String fullword="";
      String chinese="";
      String inpdate="";
      String udate="";
      keyword=request.getParameter("keyword");
      way=request.getParameter("way");
    //String addr="";
       try
      {  
      Class.forName(driverClass);
      }
      catch(Exception e)
      {
      out.println(e.getMessage());
      }   
      try
      {  
      conn  =   DriverManager.getConnection(connectUrl,"sa","");   
      st  =  conn.createStatement();
              strSQL="select * from words where properties=way";
              strSQL+="OR properties=way";
      strSQL+="AND word like '%"+keyword+"%'";
    //  out.println(strSQL);
          sqln="select count(*) from words where properties=way";
      sqln+="OR properties=way";
      sqln+="AND word like '%"+keyword+"%'";
       //  out.println(sqln);
      rsn=st.executeQuery(sqln);
           
      while(rsn.next()){
      searchnum=rsn.getInt("count(*)");
      } 
    //  out.println(searchnum);
      rsn.close();
       }
      catch(Exception ex)
      {
      out.println(ex.getMessage());
      }   
    %><%
    rs=st.executeQuery(strSQL); 
    while(rs.next()){
          properties=rs.getString("properties");
      word=rs.getString("word");
      fullword=rs.getString("fullword");
      chinese=rs.getString("chinese");
      inpdate=rs.getString("inpdate");
      udate=rs.getString("udate");
     //输出表格 
      out.println("<tr><td>");
      out.println("<li>"+properties+"</td>");
      out.println("<td>"+word+"&nbsp;</td>");
      out.println("<td>&nbsp;&nbsp;"+fullword+"&nbsp;</td>");
      out.println("<td>&nbsp;&nbsp;"+chinese+"&nbsp;</td>");
      out.println("<td>"+inpdate+"&nbsp;</td>");
      out.println("<td>"+udate+"</td>");
      out.println("</tr>");

    rs.close();
    out.println("</ul>");
    out.println("</table>");
    //out.println("共搜索到<b>"+searchnum+"</b>条记录");
    %>
    你还有ResultSet rs=null;还有放好..
    你试试用我帖出来的
    覆盖你的两处代码片段看看
      

  3.   

    把这个放到
    <%
      st.close();  
      conn.close();
    %>
    </body></html>里边。你用的<table>也不对呀,
    你先测试一下这个:
    <TABLE>
    <TR><TD>tr1</TD></TR>
    <ul>ul1</ul>
    <TR><TD>tr2</TD></TR>
    <ul>ul2</ul>
    </TABLE>
      

  4.   

    谢谢,问题解决,不过好像是因为statement对象只能创建一次,要多次用必须new statement.