if (conn!=null) conn.close();

解决方案 »

  1.   

    关闭连接前是否将结果集ResultSet关闭了吗?
      

  2.   

    try{
           if(rs!=null)
    {
           rs.close();
    }
           if(stmt!=null)
    {
           stmt.close();
    }
           if(con!=null)
    {
              con.close();
    }
        }catch(Exception e){}
    }
      

  3.   

    <%
    try{
    String url="jdbc:odbc:SELLSYSTEM";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection(url,"","");
    Statement stmt=conn.createStatement();
    String sql="select * from NEWS order by PUBLIC_DATE desc";
    ResultSet rs=stmt.executeQuery(sql);
    while((rs.next())&&(i<10)){%>
    <tr>
    <td width="30" height="20" align="right"><img src="./picture/3dot.gif"></td>
    <td>&nbsp;</td>
    <td><span class="style5"><%=rs.getString("NEWS_TITLE")%></span>&nbsp;<span class="style6"><%=rs.getDate("PUBLIC_DATE")%></span></td>
    </tr>
    <%}
    }
    catch(Exception e){
    throw(e);
    }
    try{
    if(stmt!=null) stmt.close();
    conn.close();
    }
    catch(Exception e){}%>
    这是全部的代码!
    请指教!
      

  4.   

    这个错误我昨天刚好遇到过,
    其实不难,就是你的jsp页面中有些例如(); ""之类的位置写的是中文输入法下的符号,而不是英文输入法下的符号
    你仔细检查一下
      

  5.   

    你能不能吧IE浏览器下执行这个jsp页面的出错信息贴出来
    我昨天遇到的问题跟你一模一样
      

  6.   

    An error occurred at line: 250 in the jsp file: /index.jspGenerated servlet error:
        [javac] Compiling 1 source fileD:\eclipse\workspace\Exec\work\org\apache\jsp\index_jsp.java:441: cannot resolve symbol
    symbol  : variable stmt 
    location: class org.apache.jsp.index_jsp
    if(stmt!=null) stmt.close();
               ^An error occurred at line: 250 in the jsp file: /index.jspGenerated servlet error:
    D:\eclipse\workspace\Exec\work\org\apache\jsp\index_jsp.java:441: cannot resolve symbol
    symbol  : variable stmt 
    location: class org.apache.jsp.index_jsp
    if(stmt!=null) stmt.close();
                           ^An error occurred at line: 250 in the jsp file: /index.jspGenerated servlet error:
    D:\eclipse\workspace\Exec\work\org\apache\jsp\index_jsp.java:442: cannot resolve symbol
    symbol  : variable conn 
    location: class org.apache.jsp.index_jsp
    conn.close();
            ^
    3 errorsIE中的错误是这样显示的!
      

  7.   

    先把文件index_jsp.java搜索出来
    然后用jcreator编译,看提示的错误信息Statement stmt=conn.createStatement();与if(stmt!=null) stmt.close();
    没有出现在同一个try-catch中,把后者删掉
      

  8.   

    先把try{
    if(stmt!=null) stmt.close();
    conn.close();
    }
    catch(Exception e){}
    注释掉试试
      

  9.   

    我试过了,改成这样就可以了:
    <%
    try{
    String url="jdbc:odbc:SELLSYSTEM";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection(url,"","");
    Statement stmt=conn.createStatement();
    String sql="select * from NEWS order by PUBLIC_DATE desc";
    ResultSet rs=stmt.executeQuery(sql);
    while((rs.next())&&(i<10)){%>
    <tr>
    <td width="30" height="20" align="right"><img src="./picture/3dot.gif"></td>
    <td>&nbsp;</td>
    <td><span class="style5"><%=rs.getString("NEWS_TITLE")%></span>&nbsp;<span class="style6"><%=rs.getDate("PUBLIC_DATE")%></span></td>
    </tr>
    <%}
             if(stmt!=null) stmt.close();
    conn.close();
    }
    catch(Exception e){
    throw(e);
    }%>但是谁能告诉我为什么?
      

  10.   

    我把
    Statement stmt=conn.createStatement();与if(stmt!=null) stmt.close();
    放在同一个try-catch中,就可以了!
    为什么?
      

  11.   

    我刚修改好了,你看方案一:
    <%@ page contentType="text/html;charset=gb2312" %>
    <%@ page import="java.sql.*" %>
    <%
    int i=9;
    try{
    String url="jdbc:mysql://localhost/guwan";
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection conn=DriverManager.getConnection(url,"root","");
    Statement stmt=conn.createStatement();
    String sql="select * from certificate";
    ResultSet rs=stmt.executeQuery(sql);
    while((rs.next())&&(i<10)){%>
    <tr>
    <td width="30" height="20" align="right"><img src="./picture/3dot.gif"></td>
    <td>&nbsp;</td>
    <td><span class="style5"><%=rs.getString("certificate_type")%></span></td>
    </tr>
    <%}
    }
    catch(Exception e){
    throw(e);
    }
    /*try{
    if(stmt!=null) stmt.close();
    conn.close();
    }
    catch(Exception e){}
    */
    %>
      

  12.   

    不close掉stmt和conn会有问题的!
      

  13.   

    我刚传错了,这个是:
    <%@ page contentType="text/html;charset=gb2312" %>
    <%@ page import="java.sql.*" %>
    <%Statement stmt=null;
    Connection conn=null;
    try{
    String url="jdbc:odbc:SELLSYSTEM";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn=DriverManager.getConnection(url,"","");
    stmt=conn.createStatement();
    String sql="select * from NEWS order by PUBLIC_DATE desc";
    ResultSet rs=stmt.executeQuery(sql);
    while((rs.next())&&(i<10)){%>
    <tr>
    <td width="30" height="20" align="right"><img src="./picture/3dot.gif"></td>
    <td>&nbsp;</td>
    <td><span class="style5"><%=rs.getString("certificate_type")%></span></td>
    </tr>
    <%}
    }
    catch(Exception e){
    throw(e);
    }
    try{
    if(stmt!=null) stmt.close();
    conn.close();
    }
    catch(Exception e){}%>
      

  14.   

    出错提示是这个:cannot resolve symbol说明它找不到你所用的 conn和stmt变量的位置,因为你定义在第一个try-catch中,而关闭的时候却在第二个try-catch中,所以它总报错:不能构造这个符号(变量)。明白了吧