解决方案 »

  1.   

    工程的Web.xml是这么配的:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <resource-ref>
        <description>MySQL DB Connection Pool</description>
        <res-ref-name>jdbc/DBPool</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>
     
    </web-app>
      

  2.   

    Tomcat/conf/server.xml里的相关位置是这么配的:<GlobalNamingResources>
       
        <Resource
          name="jdbc/DBPool"
          global="jdbc/DBPool"
          type="javax.sql.DataSource"
          username="root"
          password="root"
          driverClassName="com.mysql.jdbc.Driver"
          maxIdle="2"
          maxWait="5000"      
          url="jdbc:mysql://127.0.0.1:3306/test"
          maxActive="4"/>   </GlobalNamingResources>
      

  3.   

    调用ResultSet 的代码贴出来看看
      

  4.   

    Tomcat/conf/context.xml是这么配的:<?xml version='1.0' encoding='utf-8'?>
    <!-- The contents of this file will be loaded for each web application -->
    <Context>
        <!-- Default set of monitored resources -->
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <ResourceLink
       name="jdbc/DBPool" 
       type="javax.sql.DataSource" 
       global="jdbc/DBPool"  
    />
    </Context>
      

  5.   

    检查一下操作ResultSet对象的代码,看看是否引用了已关闭的结果集。
      

  6.   

    属于初学JavaWeb,写了个调用MySQL的JSP测试页如下:<%@page import="java.sql.ResultSet"%>
    <%@page import="java.sql.Statement"%>
    <%@page import="java.sql.Connection"%>
    <%@page import="java.sql.DriverManager"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" errorPage="" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>vistDBTest</title>
    </head>
    <body>
    <% //注册数据库驱动
    Class.forName("com.mysql.jdbc.Driver");
    //获取数据库连接
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
    //创建Statement对象
    Statement stmt = conn.createStatement();
    //执行查询,获取ResultSet对象
    ResultSet rs = stmt.executeQuery("select * from email");
    %>
    <table bgcolor="#9999dd" border="1" width="400">
    <%  //遍历结果集
    while(rs.next())
    //输出表格行
    out.println("<tr>");
    //输出表格列
    out.println("<td>");
    //输出结果集的第二列的值
    out.println(rs.getString(1));
    //关闭表格列
    out.println("</td>");
    //开始表格列
    out.println("<td>");
    //输出结果集的第三列的值
    out.println(rs.getString(2));
    //关闭表格列
    out.println("</td>");
    //关闭表格行
    out.println("</tr>");
    %>
    </table>
    </body>
    </html>
      

  7.   

    while(rs.next())后面加大括号啊。不然循环到第一个分号就结束了呢