日期:2014-05-17  浏览次数:20678 次

jsp配置数据池问题
首先直接在jsp页面上直接访问Mysql没问题,代码如下:
 Class.forName("com.mysql.jdbc.Driver").newInstance();
   Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/system?useUnicode=true&characterEncoding=GBK","root","123456");
   Statement stmt=con.createStatement();
    ResultSet rst=stmt.executeQuery("select * from fx_person_message");




然后配置数据池,是tomcat7,在apache-tomcat-7.0.42\conf\context.xml内容:
<?xml version='1.0' encoding='utf-8'?>
<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/mysql5" auth="Container"
              type="javax.sql.DataSource"
                          maxActive="80" maxIdle="20" maxWait="10000" removeAbandoned="true"
              username="root" password="123456"
                          driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/system" />
</Context>

还有项目本身的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>system</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <resource-ref>
                <description>Tomcat 7 DBCP</description>
                <res-ref-name>jdbc/mysql5</res-ref-name>