<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.io.*,java.sql.*" %>
<html>
<head>
<title>
daochu
</title>
</head><%!
public void daochu(){
  Connection conn=null;
   ResultSet rt=null;
  try{
  conn=DriverManager.getConnection("proxool.db");
  }catch(Exception ex){
  }
}
%> String sql="select * from tbl_user where usercode='admin'";
  Statement st=conn.createStatement();
   rt=st.executeQuery(sql);
  if(rt.next())
{
}<body>
<table width="79" height="52">
<td>
<%=rt.getString("username")%>
</td>
</table>
</body>
</html>为什么这句 <%=rt.getString("username")%>  老是提示有问题呢?? 应该怎么改呢? 歇息俄

解决方案 »

  1.   

    <table width="79" height="52"> 
    <%if(rt.next()) 

    %>
    <td> 
    <%=rt.getString("username")%> 
    </td> 
    <%
    }
    %>
    </table> 
      

  2.   

    你那样写就是错误的,
    你可以把要显现在table表格中的内容if(rs.next()){中}<table width="79" height="52"> 
    <td> 
    <% if(rt.next()) 

    rt.getString("username");

    %> 
    </td> 
    </table> 如果查询出来的数据多的话,你可以通过javaBean存到arrayList中,然后在table中显现
      

  3.   

    不行呀,还是提示 那个 rt 不是可识别的, 提示为:cannot find symbol,  怎么解决呢?这样还是不行哦?<%@ page contentType="text/html; charset=GBK" %>
    <%@ page language="java" import="java.io.*,java.sql.*" %>
    <html>
    <head>
    <title>
    daochu
    </title>
    </head><%!
    public void daochu(){
    Connection conn=null;try{
      conn=DriverManager.getConnection("proxool.db");
      
    }catch(Exception ex){
    }
    }%>
    <table>
      <td> 
      
      <%while(rs.next())
      {%>
        <%=rs.getString("username")%>
      <%}%>
    </td>
    </table>
    </html>  <% %> 这个有什么规律 或者要求吗?
      

  4.   

    没加载数据库驱动 这样也可以。。学习下
    if(rt.next()) 

    } <body> 
    <table width="79" height="52"> 
    <td> 
    <%=rt.getString("username")%>   把<%=rt.getString("username")%> 
    放到 if语句里面
      
      

  5.   

    你这种连接的数据库我没用过,conn=DriverManager.getConnection("proxool.db"); 
    但是,我感觉应该把数据库驱动加上吧?如果你之前做的不用加驱动能成功的话,你就加上关闭连接试试,<%! 
    public void daochu(){ 
    Connection conn=null; try{ 
      conn=DriverManager.getConnection("proxool.db"); 
      
    }catch(Exception ex){ 

    }%> 
    <table> 
      <td> 
      
      <%while(rs.next()) 
      {%> 
        <%=rs.getString("username")%> 
      <%}%> 
    </td> 
    </table>  <%
    try{ 
      rt.Close();
      st.Close();
      conn.Close();
      
    }catch(Exception ex){ 

    %> 
      

  6.   

     使用连接池,,在web.xml 中配置酒不要加驱动的