tomcat oracle 数据源

发布于 2024-08-15 22:01:58 字数 2084 浏览 5 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半暖夏伤 2024-08-22 22:01:58

如果异常表明它在 JNDI 上下文中找不到 jdbc,则大致意味着您

dataSource = new InitialContext().lookup("jdbc/tomdb11");

server.xmlDataSource code> 文件告诉我们以下内容:

<Resource
     name="tomdb11"
     >

这些名称相同。事实上,您应该已经使用过:

dataSource = new InitialContext().lookup("tomdb11");

但是,在 Tomcat 中,InitialContext 并不直接指向 java:comp/env/,因此您需要替换但是

dataSource = new InitialContext().lookup("java:comp/env/tomdb11");

,通常的做法是使用 jdbc 前缀指定 JDBC 数据源。因此,我会将资源重命名为

<Resource
     name="jdbc/tomdb11"
     >

并通过以下方式访问它

dataSource = new InitialContext().lookup("java:comp/env/jdbc/tomdb11");

: 在 web 应用程序的 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>

有关 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 the DataSource as follows

dataSource = new InitialContext().lookup("jdbc/tomdb11");

while your server.xml file tells the following:

<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:

dataSource = new InitialContext().lookup("java:comp/env/tomdb11");

The normal practice, however, is that you specify JDBC datasources with the jdbc prefix. 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:

<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. Hope this helps.

对你而言 2024-08-22 22:01:58

首先...确保您的 $TOMCAT_HOME/common/lib 中有一个 Oracle JDBC Jar。

其次...确保您的 web.xml 也包含这样的块...

<resource-ref>
    <description>Oracle Datasource</description>
    <res-ref-name>tomdb11</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
</resource-ref>

至于您的 ,我不确定它正在做什么,因为您已经有了这些 中定义的内容。

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...

<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>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文