[英]tomcat oracle datasource
I have apache tomcat 5.5.28 on my windows box and I am trying to deploy a web application (WAR) which works fine on other servers. 我的Windows框上有Apache Tomcat 5.5.28,我正在尝试部署一个在其他服务器上可以正常工作的Web应用程序(WAR)。
However I am having trouble creating a datasource. 但是我在创建数据源时遇到了麻烦。 I am not sure of the format. 我不确定格式。 The db is oracle. 该数据库是oracle。
Here is what I have in server.xml. 这是server.xml中的内容。
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
name="tomdb11"
type="oracle.jdbc.pool.OracleDataSource"
maxActive="4"
maxIdle="2"
username="tomdb11"
maxWait="5000"
driverClassName="oracle.jdbc.driver.OracleDriver"
validationQuery="select * from dual"
password="remotedb11"
url="jdbc:oracle:thin:@dbserver:1521:orcl"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml"/>
</GlobalNamingResources>
How do I access this in the web.xml where usually what I have which works in other servers is 我如何在web.xml中访问此文件,通常我在其他服务器上可以使用的文件是
<context-param>
<param-name>databaseUser</param-name>
<param-value>tomdb11</param-value>
</context-param>
<context-param>
<param-name>databasePassword</param-name>
<param-value>tomdb11</param-value>
</context-param>
<context-param>
<param-name>databaseSchema</param-name>
<param-value>TOMDBADMINN11</param-value>
</context-param>
Also am I missing something? 我还缺少什么吗?
Edit : I get the following exception: 编辑 :我得到以下异常:
javax.naming.NameNotFoundException: Name tomdb11 is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.taw.database.DatabaseService.<init>(DatabaseService.java:19)
at com.taw.database.DatabaseServices.init(DatabaseServices.java:40)
If exception tells that it cannot find jdbc
in the JNDI context, then it roughly means that you tried to obtain the DataSource
as follows 如果异常表明它无法在JNDI上下文中找到jdbc
,则大致意味着您尝试按以下方式获取DataSource
dataSource = new InitialContext().lookup("jdbc/tomdb11");
while your server.xml
file tells the following: 而您的server.xml
文件告诉以下内容:
<Resource
name="tomdb11"
>
Those names are not the same. 这些名称不相同。 In fact, you should have been used: 实际上,您应该已经使用过:
dataSource = new InitialContext().lookup("tomdb11");
In Tomcat, however, the InitialContext
doesn't directly point to java:comp/env/
, so you'll need to replace it by: 但是,在Tomcat中, InitialContext
并不直接指向java:comp/env/
,因此您需要将其替换为:
dataSource = new InitialContext().lookup("java:comp/env/tomdb11");
The normal practice, however, is that you specify JDBC datasources with the jdbc
prefix. 但是,通常的做法是使用jdbc
前缀指定JDBC数据源。 So I would rename the resource as 所以我将资源重命名为
<Resource
name="jdbc/tomdb11"
>
and access it by 并通过访问
dataSource = new InitialContext().lookup("java:comp/env/jdbc/tomdb11");
In the webapp's web.xml
you should however also have the following resource declaration: 但是,在webapp的web.xml
您还应该具有以下资源声明:
<resource-env-ref>
<resource-env-ref-name>jdbc/tomdb11</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
For more details about Tomcat JNDI check this HOWTO: http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html . 有关Tomcat JNDI的更多详细信息,请参见以下HOWTO: http : //tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html 。 Hope this helps. 希望这可以帮助。
First... Make sure you have an Oracle JDBC Jar in your $TOMCAT_HOME/common/lib. 首先...确保$ TOMCAT_HOME / common / lib中有一个Oracle JDBC Jar。
Second... Make sure your web.xml also contains a block like this... 第二...确保您的web.xml也包含这样的块...
<resource-ref>
<description>Oracle Datasource</description>
<res-ref-name>tomdb11</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
</resource-ref>
As for your <context-param>
, I'm not sure that is doing anything as you already have those things defined in your <Resource>
. 至于您的<context-param>
,我不确定您正在做任何事情,因为您已经在<Resource>
定义了这些内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.