File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Java Products and Servers and the fly likes Naming Exception happened when trying to connect to Oracle in Sun One Application Ser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Naming Exception happened when trying to connect to Oracle in Sun One Application Ser" Watch "Naming Exception happened when trying to connect to Oracle in Sun One Application Ser" New topic
Author

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

Dave Gear
Greenhorn

Joined: Feb 16, 2004
Posts: 13
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?
Dominik Ratajski
Greenhorn

Joined: Feb 09, 2004
Posts: 14
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

Joined: Feb 16, 2004
Posts: 13
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

Joined: Feb 09, 2004
Posts: 14
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Naming Exception happened when trying to connect to Oracle in Sun One Application Ser
 
Similar Threads
How to configure hsqldb in struts 1.3.8?
Problem using DataSource with core java app
setting DataSource in J2ee
Looking up DataSource
Coonection pooling in WAS6.1