How do I connect to a Websphere Datasource with a given JNDI name?

前端 未结 6 1495
温柔的废话
温柔的废话 2020-12-07 23:15

I\'m using Websphere Portal 7.0 and creating a portlet with RAD 8.0. My portlet is trying to make a db2 connection to a remote server. I wrote a java program locally to do a

6条回答
  •  情话喂你
    2020-12-08 00:06

    DNS for Services

    JNDI needs to be approached with the understanding that it is a service locator. When the desired service is hosted on the same server/node as the application, then your use of InitialContext may work.

    What makes it more complicated is that defining a Data Source in Web Sphere (at least back in 4.0) allowed you to define the visibility to various degrees. Basically it adds namespaces to the environment and clients have to know where the resource is hosted.

    Simple example.

    javax.naming.InitialContext ctx = new javax.naming.InitialContext();
    DataSource ds = (DataSource) ctx.lookup("java:comp/env/DataSourceAlias");
    

    Here is IBM's reference page.

    If you are trying to reference a data source from an app that is NOT in the J2EE container, you'll need a slightly different approach starting with needing some J2EE client jars in your classpath. http://www.coderanch.com/t/75386/Websphere/lookup-datasources-JNDI-outside-EE

提交回复
热议问题