server.xml:
<Resource name="jdbc/test" auth="SERVLET"
                    type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/test">
            <parameter><name>user</name><value>aa</value></parameter>
            <parameter><name>password</name><value>bb</value></parameter>
            <parameter><name>driverClassName</name>
              <value>com.caucho.jdbc.mysql.Driver</value></parameter>
            <parameter><name>driverName</name>
              <value>jdbc:mysql-<value>caucho://localhost:3306/test</value></parameter>
          </ResourceParams>jsp:
Context env;
DataSource source;
Connection conn = null;
try{
env= (Context) new InitialContext().lookup("java:comp/env");
source= (DataSource) env.lookup("jdbc/test");
conn = source.getConnection();
...
}

解决方案 »

  1.   

    我已配置完成,可是访问时为何提示:Exception creating DataSource: org.hsql.jdbcDriver
      

  2.   

    你需要同时在server.xml和你的web.xml进行配置.
    server.xml中的配置楼上的已讲了,我就说说在web.xml下的配置吧
    <resource-ref>
    <res-ref-name>jdbc/mysql</res-ref-name>  
             //这个值应和你在servel.xml中配置的值一致
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    这样配置好后就可以在程序中使用了(我就是这样用的)
      

  3.   

    我是这样配置的啊,我测试过,我的jsp是这样的:<%@ page contentType="text/html; charset=Shift_JIS" %>
    <%@ page import="javax.naming.Context" %>
    <%@ page import="javax.sql.DataSource"%>
    <%@ page import="javax.naming.InitialContext"%>
    <%@ page import="java.sql.*"%><%
      DataSource ds = null;
      Connection conn = null;
      try{
        
    Context initCtx = new InitialContext();

        Context envCtx = (Context) initCtx.lookup("java:comp/env");

        ds = (DataSource)envCtx.lookup("jdbc/mysql");

        conn = ds.getConnection();

        if(conn!=null)
            out.println("Connection is OK!");
        else
            out.println("Connection Failed!");

       }catch(Exception e){
    out.println(e.getMessage());
       }
    %>
    是运行到:ds = (DataSource)envCtx.lookup("jdbc/mysql"); 出错的。
      

  4.   

    我在solaris上也碰到了这个问题,将hsql的设置都去掉了,它还是要去找hsql的驱动,同样的设置在linux下没什么问题,能够正常运行的,你用的什么操作系统?
      

  5.   

    在你的web.xml中是否还有其它的配置.我有一次也遇到过同样的情况,是因为我在其中配置了taglib,结果就有错误.后来折腾了半天,无意中把taglib和resource-ref的位置对调了一下,结果一下就搞定了.不知道你是否也碰到了同样的情况.祝你好运.
      

  6.   

    <resource-ref>在<taglib>之后,<security-constraint>之前。
    另,真的是连接池吗?怎样设置最大、最小连接数?
      

  7.   

    我可帮你,
    如果你需要,mailto:[email protected]