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?
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.
Joined: Feb 16, 2004
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,
Joined: Feb 09, 2004
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.
subject: Naming Exception happened when trying to connect to Oracle in Sun One Application Ser