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
<?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
解决方案 »
- Extjs解析struts2返回的json数据错误求大虾给指点一下 谢谢啦。(分不多了,不好意思)。很急急急的
- jsp救急
- jsp编程 用什么软件写程序比较好?
- 我有一个JSP文件,和一个JAVA的BEAN,什么目录结构去放这二个文件??感谢。初学JSP
- 哭求用JBuilderX写的一个使用Strus的例子(100分,不够可再加)
- 求救!!
- JavaScript可否设置/访问剪贴板中的数据,该如何?
- 写的一个类,在JSP中引入时总是说找不到,什么原因?
- page编译指令的作用域?
- 求大神帮我看看ftp不能启动的问题....
- 请教高手Hibernate错误问题
- 如何同时清除多台Web Server上的cache?
<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"/>
是因为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();
<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"/>
commons-collections-3.2.1.jar
commons-pool-1.5.4.jar
postgresql-8.3-603.jdbc3.jar
四个文件都放到/opt/tomcat/lib/下面了现在还是没有解决问题,但奇怪的是,同样的配置,在我的笔记本上的netbeans里确运行正常
JDBC驱动找不到。访问数据库URL为空