• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Naming Exception happened when trying to connect to Oracle in Sun One Application Ser

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Naming Exception happened at the following point.
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/jdbc-oracle");

In Sun One Application Server, I set up the JDBC Resource: jdbc/jdbc-oracle, which is based on the Connection Pool OraclePool. For this OraclePool, I set up 3 properties: user: system, password: manager, and url: jdbc racle:thin:@localhost:1521:myDB.

Anybody can find out what�s the problem here? Why there is always Naming Exception when DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/jdbc-oracle") is called?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you set up the sun-web.xml with the mapping of the object type and the logical datasource?

web.xml
<resource-ref>
<res-ref-name>jdbc/logical_ds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


sun-web.xml
<resource-ref>
<res-ref-name>jdbc/logical_ds</res-ref-name>
<jndi-name>jdbc/physical_ds</jndi-name>
</resource-ref>

to use the full java:comp... etc you need to set up the sun-web.xml deployment mapping, otherwise if you use just "jdbc/jdbc-oracle" (assuming this is your jndi connection pool name) to connect directly to the connection pool.

DSR
 
Dave Gear
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Dominik :

Thank you very much for your reply.

But I still have 2 questions:
1)in the Sun-Web.xml file you showed me here, for the
<res-ref-name>jdbc/logical_ds</res-ref-name>
<jndi-name>jdbc/physical_ds</jndi-name>
I�m not very clear about what the logical_ds and physical_ds, could you show me more deeply? For my case, I have created the connection pool: OraclePool and JDBC Datasource, the JNDI Name for it is: jdbc/jdbc-oracle. So, could you use my specific example on how to set up <res-ref-name> and <jndi-name> here?
2)What you mention here is web.xml and sun-web.xml, but if I don�t use any web-based client, for example, I just create a normal java test code to test my bean, in other words, there are no web.xml and sun-web.xml at all, how can I do here? Should I do the same thing in some other xml files? So could you tell me which files I should deal with?

Thanks a lot,
 
Dominik Ratajski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the sun-web.xml is used for deployment time mapping on sun application server (AS).

it's to ensure that if the jdbc pool changes on the server that the application can be modified at deployment time. it should be in your WEB-INF directory.

jdbc/logical_ds is the name call you make using the jndi name in your code:
ie DataSource ds = Context.lookup("java:comp/env/jdbc/logical_ds");

the physical_ds is the name of the connection pool that you defined on the server (in your case this is jdbc/jdbc-oracle).

i've mentioned the sun-web.xml as this is the Sun AS forum. i'm not sure by what you mean by a web based client - if it's a server based connection pool a client based bean will not have access to it. if it's a server based bean it should be the same although i haven't tried it.

you should be able to access the pool directly by calling:
DataSource ds = Context.lookup("jdbc/physical_ds");
or specific to your jndi name:
DataSource ds = Context.lookup("jdbc/jdbc-oracle");
however you will notice some error messages about cannot locate object or something similar althought it will still work. doing the lookup ("java:comp/env...") with the mapping is the correct way to do it.

DSR
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic