aspose file tools*
The moose likes Oracle/OAS and the fly likes JDBC lookup failure through java:comp.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "JDBC lookup failure through java:comp...." Watch "JDBC lookup failure through java:comp...." New topic
Author

JDBC lookup failure through java:comp....

Subadhra Velu
Greenhorn

Joined: Jul 01, 2004
Posts: 4
I have just started using oracle9iAS . I am able to access my datasource from a Java client with the following code:
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.PROVIDER_URL,"ormi://localhost");
env.put(Context.SECURITY_PRINCIPAL,"admin");
env.put(Context.SECURITY_CREDENTIALS,"ignite");
InitialContext ic = new InitialContext(env);
DataSource ds = (DataSource)ic.lookup("jdbc/OracleTestCoreDS");
System.out.println("Data source is : "+ds);

But the EJB-suggested way of looking up : "jva:comp/env/jdbc/OracleTestCoreDS" in my ic.lookup parameter is not working.
I have added the following resource-ref tag to my application-client.xml:
<resource-ref>
<res-ref-name>jdbc/OracleTestCoreDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth></resource-ref>

Can anyone let me know where i am going wrong? If the first lookup is working the proper registration of the data source is complete right? Is Any other orion specific file modification is required.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Welcome to Javaranch Subadhra Velu.

I'm guessing that you meant to ask this question in the Oracle forum, so I'll move it over there.

Hang on...


Pauline

oracle? orion? kinda like sweden and switzerland, they get mixed up all the time...
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Subadra,

There is a typo in the above. "jva" should be "java". Was it just a typo in this post or in the code too?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Subadhra Velu
Greenhorn

Joined: Jul 01, 2004
Posts: 4
thanks for your reply...The error is only in the post... The code has the proper syntax.... I figured the answer out... I was using the wrong context factory... Since i had to access from java client i was supposed to use Applicationclientcontextfactory...... So,now it works.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Thanks for posting the solution so others reading this thread can learn what the answer was.
oman tel
Greenhorn

Joined: Jul 28, 2004
Posts: 2
Hello Subadhra,

I get the same exception as you get can you tell me what user name & password should i give for the
Context.SECURITY_PRINCIPAL and Context.SECURITY_CREDENTIALS

Now i'm giving the user name and password that i give to login into Oracle App Server





private HelloHome lookupHome()throws NamingException
{
// Lookup the beans home using JNDI
Context ctx = getInitialContext();
try
{

Object home = ctx.lookup(JNDI_NAME); // Getting error here
return (HelloHome) narrow(home, HelloHome.class);
}
catch (NamingException ne)
{
log(ne.toString());
log("The client was unable to lookup the EJBHome. Please make sure ");
log("that you have deployed the ejb with the JNDI name "+JNDI_NAME+" on the server at "+url);
throw ne;
}
}

private Context getInitialContext() throws NamingException
{
try
{
// Get an InitialContext
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.ApplicationClientInitialContextFactory");
//
h.put(Context.PROVIDER_URL, url);//ormi:localhost:23791
h.put(Context.SECURITY_PRINCIPAL, "ias_admin");
h.put(Context.SECURITY_CREDENTIALS, "system12");
return new InitialContext(h);
}
catch (NamingException ne)
{
log (ne.toString());
log("We were unable to get a connection to the server at "+url);
log("Please make sure that the server is running.");
throw ne;
}
}




java.lang.InstantiationException: Error communicating with server: Lookup error:
java.net.ConnectException: Connection refused: connect; nested exception is:
java.net.ConnectException: Connection refused: connect; nested exception
is:
javax.naming.NamingException: Lookup error: java.net.ConnectException: C
onnection refused: connect; nested exception is:
java.net.ConnectException: Connection refused: connect [Root exception i
s java.net.ConnectException: Connection refused: connect]
at com.evermind.server.ApplicationClientContext.createContext(Applicatio
nClientContext.java:61)
at com.evermind.server.ApplicationClientInitialContextFactory.getInitial
Context(ApplicationClientInitialContextFactory.java:155)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at Client.getInitialContext(Client.java:111)
at Client.lookupHome(Client.java:80)
at Client.<init>(Client.java:22)
at Client.main(Client.java:33)
javax.naming.NamingException: Error reading application-client descriptor: Error
communicating with server: Lookup error: java.net.ConnectException: Connection
refused: connect; nested exception is:
java.net.ConnectException: Connection refused: connect; nested exception
is:
javax.naming.NamingException: Lookup error: java.net.ConnectException: C
onnection refused: connect; nested exception is:
java.net.ConnectException: Connection refused: connect [Root exception i
s java.net.ConnectException: Connection refused: connect]
We were unable to get a connection to the server at ormi://localhost:23791
Please make sure that the server is running.
[ July 28, 2004: Message edited by: oman tel ]
Subadhra Velu
Greenhorn

Joined: Jul 01, 2004
Posts: 4
Hi Oman,
By going through the exception stack ... just verify the following before proceeding any further..
1. that the server has been started properly... just restart to make sure
2. Since you are using ApplicationClientInitialContextFactory you must have an application-client.xml inside meta-inf folder parallel to your client class file
3. you are looking up an ejb. So, you have to specify the application name along with the url ... so your url should be ormi://localhost:23791/appname.
The application name is the name that the entry in the server.xml has been made with.
4. using the oracle app server's principal and credential should be fine. Put a little SOP and try out. If there is problem with principal and credential the error will be thrown during creating the initial context itself.Since you are saying the error is thrown during the lookup check out the provider url once again...
oman tel
Greenhorn

Joined: Jul 28, 2004
Posts: 2
How to restart it & how to find the admin pwd .

Can u give you'r mail id .. so that i can send my jar to u .
I'm struggling for this for a couple of days.
Else can u plz send a mail to me

Srini
[ July 29, 2004: Message edited by: oman tel ]
 
 
subject: JDBC lookup failure through java:comp....