很郁闷...我搞了一个星期都搞不好.. 网上的不是少了一点,就是copy and paste人家的..  今日跟住网上一篇文章做了一下.. 我用的是tomcat-5.5.23 和sql server 2005 我先再%tomcat_home%/common/lib中加入SQL2005的JDBC DRIVER 
然后在%tomcat_home%/conf/server.xml </host> 里 加入 <Context path="/AVG" docBase="AVG" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/avg" auth="Container" type="javax.sql.DataSource"
    maxActive="100" maxIdle="30" maxWait="10000"
    username="chessman_mak" password="chessman" 
    driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    url="jdbc:sqlserver://localhost"/>
<ResourceLink global="jdbc/avg" name="jdbc/avg" type="javax.sql.DataSource"/> 
</Context>然后在项目的web-inf下的web.xml里加入<resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/avg</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
</resource-ref>在测试中..我用这三句来连接InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/avg");但是..还是出错了...  org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'网上说吧DRIVER入进COMMON/LIB中就OK了. . 但是我还是遇到这个问题了. .  郁闷请大侠们教教我吧..  
谢谢..  

解决方案 »

  1.   

    有一些文章说要把 
    <Resource name="jdbc/avg" auth="Container" type="javax.sql.DataSource" 
        maxActive="100" maxIdle="30" maxWait="10000" 
        username="chessman_mak" password="chessman" 
        driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
        url="jdbc:sqlserver://localhost"/> 加在 server.xml里的 <GlobalNamingResources>  中  有些说加在<host>中..  那个才对呢??
      

  2.   

    context.xml 文件
    -------------------------------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <Context antiJARLocking="true" path="/myjsp" URIEncoding="UTF-8">
      <Resource name="jdbc/myjdbc"
      auth="Container"
      description="DB Connection"
      driverClassName="com.mysql.jdbc.Driver"
      maxActive="500"
      maxIdle="30"
      maxWait="10000"
      type="javax.sql.DataSource"
      username="user1"
      password="123456"
      url="jdbc:mysql://localhost:3306/mydb?autoReconnect=true"
      />
    </Context>
    =====================================================
    win.xml
    ----------------------------------------------------------------------
    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/myjdbc</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>
      

  3.   

    简要代码如下Connection con;
    Statement stmt;
    ResultSet rs;try
    {
      Context ctx = new InitialContext ();
      DataSource ds = (DataSource) ctx.lookup ("java:comp/env/jdbc/myjdbc");
      con = ds.getConnection ();
      stmt = con.createStatement ();
      String SqlCmdText = String.format (" ...... // 你的 SQL  int i = stmt.executeUpdate (SqlCmdText);  // 执行 insert update 等
      // 或者
      rs = stmt.executeQuery(SqlCmdText); // select ,带反馈结果的使用方法
      

  4.   

    连接 sql 2005 的 context.xml 文件,其它的都一样
    SQL2005 还有个问题,默认并没有开启 TCP 连接,只支持管道命名,所以需要在配制里启动TCP连接方式,再重新启动数据库<?xml version="1.0" encoding="UTF-8"?>
    <Context path="/openinfo" URIEncoding="UTF-8">
      <Resource
        description="DB Connection"
        driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
        maxActive="500"
        maxIdle="30"
        maxWait="10000"
        name="jdbc/myjdbc"
        auth="Container"
        type="javax.sql.DataSource"  
        username="user1"
        password="123456"
        url="jdbc:sqlserver://localhost:1433;databaseName=MyDB"
      />  
    </Context>
      

  5.   


    楼上, 我根据你的方式改了也不行...  555  我郁闷死了..  你说TCP连接方式 ???   .....  是什么东东??  怎样改?
      

  6.   

    我也碰到类似的问题,我用的是mysql
    郁闷好多天了