这是昨晚一直未能解决的问题,现在写出来,供大家参考,看能否有好的解决办法:
注:我只把关键的地方贴出来了:
String id;
String title;
String content;
String sql="select * from news order by id desc";
rs=smt.executeQuery(sql);
while(rs.next)
{
id=rs.getString("id");
content=rs.getString("content");
out.print(content);
sql="select * from fj where id='"+id+"'";
rs=smt.executeQuery(sql);
while(rs.next())
{
title=rs.getString("title");
out.print(title)
}
}
这句代码的意思是从表news里把这它的content读出来并显示,同时再读出另一个表fj的title,因为news里包含有fj的id,所以先读news并循环输出,结果出错了:
Invalid column name: name
经详细检查,数据库语句都没有错,代码也是正确的,两个合在一起就出了问题,有哪位大侠帮忙出点主意呢?

解决方案 »

  1.   

    对不起,刚才写的时候漏了括号,我的程序里是有括号的,但是还是出现:
    Invalid  column  name:  name
      

  2.   

    拜托做一下try catch,把错误堆栈给打出来看看.
      

  3.   

    <%@page contentType="text/html;charset=gb2312"%>
    <%@include file="conn.jsp"%>
    <%@page import="page.Page"%>
    <%@page import="java.util.Vector"%>
    <%@page import="java.text.*"%>
    <%@page import="com.ntsky.note.*"%>
    <html>
    <head>
    <title>附件管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link href="inc/style.css" rel="stylesheet" type="text/css">
    <link href="../stytle/style.css" rel="stylesheet" type="text/css">
    </head>
    <div align="center">
      <IFRAME 
      src="manageban.jsp" frameBorder=0 
      width=777 scrolling=no 
      height=153>
      </IFRAME>
    </div><script language="JavaScript">
    function delfj(name){
    var question="你真的要删除' "+name+" '吗?";
    var bb=confirm(question);
    if (bb==true)
    return true;
    else
    return false;
    }
    </script><body background="../images/jfbg.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <%
    String getPage;
    String usr=(String)session.getValue("username");
    if(usr==null||usr=="")
    {
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    String newLocn = "../error.jsp?errorid=6";
    response.setHeader("Location",newLocn);
    out.close();
    }
    getPage=request.getParameter("pageId").trim();
    if(getPage==null||getPage=="")
    {getPage="";
    }
    int i=0;
    if(getPage.compareTo("")==0)
    {
    Page myPage=new Page();sql="select * from fj where user1='"+usr+"' order by id desc";
    rs=smt.executeQuery(sql);
      myPage.pageCount=0;
      myPage.recordCount=0;
      myPage.pageId=1;
      myPage.pageSize=15;
      Vector idList=new Vector();
      getPage="1";
      int b=0;
      while(rs.next())
       {
       myPage.recordCount++;
       b++;
       if(myPage.recordCount==myPage.pageSize)
         {
              myPage.pageCount++;
     idList.addElement(rs.getString("id"));
     myPage.recordCount=0;  
          }     
        }
    if(myPage.recordCount!=0) myPage.pageCount++;
    myPage.recordCount+=(myPage.pageCount-1)*myPage.pageSize;
    rs.close();session.putValue("idList",idList);
    session.putValue("myPage",myPage);}boolean pageError=false;
    Page myPage=(Page)session.getValue("myPage");
    if(myPage.recordCount<0)
    {
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    String newLocn = "../error.jsp?errorid=8";
    response.setHeader("Location",newLocn);
    out.close();
    }
    else
     //查询结果不为空
     {
    int pageId=myPage.pageId;
    if(getPage!=null&&getPage!="") pageId=Integer.parseInt(getPage.trim());
    if(pageId<1||pageId>myPage.pageCount)
    {
    pageId=myPage.pageId;
    pageError=true;
    }
    myPage.pageId=pageId;
    Vector idList=(Vector)session.getValue("idList");
    String getList="";
    if(pageId>1)
    {
    getList=(String)idList.elementAt(pageId-2);
    getList="  and id<"+getList;
    }
    sql="select top"+" "+myPage.pageSize+" "+" * from fj where user1='"+usr+"'";
    sql=sql+" "+getList+" order by id desc";
    rs=smt.executeQuery(sql);
    %>
    <table width="777" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
      <tr> 
        <td height="5"></td>
      </tr>
      <tr> 
        <td colspan="2"><font color="#FFFFFF">当初位置:<a href="index.jsp" class="g2">后台管理</a>-&gt;<a href="managenews.jsp?pageId=" class="g2">新闻管理</a>-&gt;我的附件管理器</font></td>
        <td width="479"><a href="addnews.jsp" class="g2">新闻发布</a><font color="#FFFFFF">&nbsp;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FFFFFF">&nbsp;&nbsp;修改新闻请到<a href="myfiles.jsp" class="g2">&nbsp;&nbsp;&nbsp;我的文件夹</a></font></td>
      </tr>
      <tr> 
        <td height="5"></td>
      </tr>
    </table>
    <table width="777" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
      <tr> 
        <td height="30" bgcolor="#FF6633"><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
            <tr bgcolor="#000000"> 
              <td width="51" height="29" ><div align="center"><font color="#FFFFFF">序号</font></div></td>
              <td width="58" height="30"><div align="center"><font color="#FFFFFF">所属新闻</font></div></td>
              <td width="145"><div align="center"><font color="#FFFFFF">原名字</font></div></td>
              <td width="62"><div align="center"><font color="#FFFFFF">大小</font></div></td>
              <td width="293"><div align="center"><font color="#FFFFFF">附件说明</font></div></td>
              <td width="51"><div align="center"><font color="#FFFFFF">作者</font></div></td>
              <td width="52"><div align="center"><font color="#FFFFFF">查看</font></div></td>
              <td width="54"><div align="center"><font color="#FFFFFF">删除</font></div></td>
            </tr>
            <%while(rs.next())
    {     
    String newsid;
      String title;
      String name;
      String yname;
      String ext;
      String size;
      String fcontent;
      String user1;
      i=i+1;
          String id=(String)rs.getString("id");
      name=(String)rs.getString("name").trim();
     yname=(String)rs.getString("yname");
      ext=(String)rs.getString("ext");
      size=(String)rs.getString("siz").trim();
           fcontent=(String)rs.getString("fcontent");
     user1=(String)rs.getString("user1");
     newsid=(String)rs.getString("newsid").trim();
      %>
            <tr bgcolor="#999999"> 
              <td height="29" ><div align="center"> 
                  <%
      if(pageId>1)
      {
      int count=myPage.pageSize*(pageId-1)+i;
      out.print(count);
      }
      else
      {
      out.print(i);
      }
      %>
                </div></td>
              <td height="30"><div align="center"><%
      
      sql="select * from news where id='"+newsid+"'";
      rs=smt.executeQuery(sql);
      
      
    %></div></td>
              <td><div align="center"> 
                  <%=yname%>
                </div></td>
              <td> <div align="center"> 
                  <%
      double a=Integer.parseInt(size);
      if(Arith.div(a,1024,3)>1000)
      {
        out.print(Arith.div(a,1048576,3));
      out.print("<font color=white>MB</font>");
      }
      else
      {
      out.print(Arith.div(a,1024,3));
      out.print("<font color=white>KB</font>");
      }
      
      %>
                </div></td>
              <td><div align="center"><%=fcontent%></div></td>
              <td><div align="center"><%=user1%></div></td>
              <td><div align="center"><a href="../upload/<%=name%>">查看</a></div></td>
              <td><div align="center"><a href="delfj.jsp?newsid=<%=id%>" onClick="return delfj('标题为:<%=name%>')">删除</a></div></td>
            </tr>
            <%}%>
          </table>
       
          
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="25"> <div align="center">
                  <%
    if(pageId!=1)
    {
    %>
                  <a href="fjmanage.jsp?pageId=1"><font color="#FFFFFF">第一页</font></a><font color="#FFFFFF">|<a href="fjmanage.jsp?pageId=<%=pageId-1%>">上一页</a>| 
                  <%}else{%>
                  第一页|上一页| 
                  <%}
    if(pageId!=myPage.pageCount)
    {%>
                  <a href="fjmanage.jsp?pageId=<%=pageId+1%>">下一页</a>| 
                  <a href="fjmanage.jsp?pageId=<%=myPage.pageCount%>">最后一页</a> 
                  <%}else{%>
                  下一页|最后一页 
                  <%
    }
    %>
                  当前 <%=pageId%></b>/ <b><%=myPage.pageCount%> 
                  <%   }%>
                  </b></font></div></td>
            </tr>
          </table>
          
        </td>
      </tr>
    </table>
    <hr size="1" id="5">
    <div align="center">
      <IFRAME 
                                  src="../botton.htm" frameBorder=0 
                                  width=777 scrolling=no 
                              height=80></IFRAME></div></body>
    </html>
      

  4.   

    有点乱,因为当中有个分页,现有些 html的东东
      

  5.   

    你把两个人所rs换成不同的resuletSet对象,估计因该没有错误!
      

  6.   

    fj这个表里面有name这个字段吗?
      

  7.   

    你的两个while语句里面的rs是同一个!
    当第二个rs重新赋值的时候实际上已经把第一个rs的值给改了!再回到第一个(外层)while的时候其中的rs已经是
    sql="select * from fj where id='"+id+"'";
    rs=smt.executeQuery(sql);
    执行后的rs了,而你的fj表里面应该是没有name字段的,当然报错了!
    处理方法,重新定义第二rs: 
    sql="select * from fj where id='"+id+"'";
    ResultSet rs1 = smt.executeQuery(sql);
    使两个while所用的rs是不同的就可以解决问题了!
      

  8.   

    你这个是存在前一个记录集被后一个覆盖的问题,再次运行你的rs就是最后那个了。也就是你的rs被赋于了一个新的结果集。
    例:
    第一次
    第一个while   rs=1
    第二个while   rs=2第二次
    第一个while   rs=2
      

  9.   

    把news和fj表通id连接不就行了嘛,这样写也太麻烦了吧