- 论坛徽章:
- 1
|
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 |
|