tomcat连接池在服务器上出错,但在本机上运行正常IDE用的NetBeans,配置文件如下:context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/" docBase="" crossContext="true" reloadable="true" debug="1">
  <Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/rlzydata?autoReconnect=true" username="abc" password="abc" maxActive="100" maxIdle="20" />
</Context>web.xml中加入:
<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
java文件:
public Connection Connect() throws NamingException, Exception {
        Connection conn=null;
        Context initCtx = new InitialContext();
        javax.sql.DataSource ds =(javax.sql.DataSource)initCtx.lookup("java:comp/env/jdbc/postgres");
        conn=ds.getConnection();
        return conn;
    }----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------在NetBeans里运行时正常,但上传到服务器上后出错

以上配置文件都在项目里,jsp页面能打开,但不能访问数据库
出错提示:Cannot create JDBC driver of class '' for connect URL 'null'如果把下面内容加在tomcat下的web.xml文件中,则连jsp页面都不能打开
<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>如果tomcat下的web.xml和项目的web.xml都不加上面的内容,则能打开jsp页面,但连接数据库时提示:
Name jdbc is not bound in this Context

解决方案 »

  1.   

    context.xml配置信息如下: 
     <Resource name="jdbc/books" 
        auth="Container" 
        type="javax.sql.DataSource"
        maxActive="1000"
        maxIdle="1000"
        maxWait="1000" 
        username=""
        password="" 
        driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
        url="jdbc:sqlserver://localhost:1433;DatabaseName=books"/>
      

  2.   

    Cannot create JDBC driver of class '' for connect URL 'null' 
    是因为jdbc驱动没有复制到Tomact的common\lib目录下?在使用lookup()方法查找数据源时,参数是“前缀+数据源名称”,如果没有写前缀,则会出现你所述的错误
    Name jdbc is not bound in this Context
    请看:
    //使用JNDI读取Tomact安装目录/conf/context.xml文件中的数据源
    Context ic = new InitialContext(); 
    DataSource ds = (DataSource)ic.lookup("java:comp/env/jdbc/postgres");
    //通过JNDI读取的数据源建立数据库连接
    Connection con = ds.getConnection();
      

  3.   

    context.xml配置信息如下: 
    <Resource name="jdbc/books" 
        auth="Container" 
        type="javax.sql.DataSource" 
        maxActive="1000" 
        maxIdle="1000" 
        maxWait="1000" 
        username="" 
        password="" 
        driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
        url="jdbc:sqlserver://localhost:1433;DatabaseName=books"/>
      

  4.   

    Cannot create JDBC driver of class '' for connect URL 'null' 没有找到驱动
      

  5.   

    commons-dbcp-1.2.2.jar
    commons-collections-3.2.1.jar
    commons-pool-1.5.4.jar
    postgresql-8.3-603.jdbc3.jar
    四个文件都放到/opt/tomcat/lib/下面了现在还是没有解决问题,但奇怪的是,同样的配置,在我的笔记本上的netbeans里确运行正常
      

  6.   

    Cannot create JDBC driver of class '' for connect URL 'null' 
    JDBC驱动找不到。访问数据库URL为空
      

  7.   

    jar没导入?环境变量不对?顶
      

  8.   

    你连个环境的tomcat版本一致吗?