tomcat oracle 数据源
我的 Windows 机器上有 apache tomcat 5.5.28,我正在尝试部署一个在其他服务器上运行良好的 Web 应用程序(WAR)。
但是我在创建数据源时遇到问题。我不确定格式。数据库是oracle。
这是我在 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>
我如何在 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>
我还缺少一些东西吗?
编辑:我收到以下异常:
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)
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.
However I am having trouble creating a datasource. I am not sure of the format. The db is oracle.
Here is what I have in 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
<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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果异常表明它在 JNDI 上下文中找不到
jdbc
,则大致意味着您在
server.xmlDataSource
code> 文件告诉我们以下内容:这些名称不相同。事实上,您应该已经使用过:
但是,在 Tomcat 中,
InitialContext
并不直接指向java:comp/env/
,因此您需要替换但是,通常的做法是使用
jdbc
前缀指定 JDBC 数据源。因此,我会将资源重命名为并通过以下方式访问它
: 在 web 应用程序的
web.xml
中,您还应该具有以下资源声明:有关 Tomcat JNDI 的更多详细信息,请查看此 HOWTO:http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources- howto.html。希望这有帮助。
If exception tells that it cannot find
jdbc
in the JNDI context, then it roughly means that you tried to obtain theDataSource
as followswhile your
server.xml
file tells the following:Those names are not the same. In fact, you should have been used:
In Tomcat, however, the
InitialContext
doesn't directly point tojava:comp/env/
, so you'll need to replace it by:The normal practice, however, is that you specify JDBC datasources with the
jdbc
prefix. So I would rename the resource asand access it by
In the webapp's
web.xml
you should however also have the following resource declaration:For more details about Tomcat JNDI check this HOWTO: http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html. Hope this helps.
首先...确保您的 $TOMCAT_HOME/common/lib 中有一个 Oracle JDBC Jar。
其次...确保您的 web.xml 也包含这样的块...
至于您的
,我不确定它正在做什么,因为您已经有了这些
中定义的内容。First... Make sure you have an Oracle JDBC Jar in your $TOMCAT_HOME/common/lib.
Second... Make sure your web.xml also contains a block like this...
As for your
<context-param>
, I'm not sure that is doing anything as you already have those things defined in your<Resource>
.