aspose file tools*
The moose likes BEA/Weblogic and the fly likes NamingException when trying to get a datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "NamingException when trying to get a datasource" Watch "NamingException when trying to get a datasource" New topic
Author

NamingException when trying to get a datasource

Luca Zitto
Greenhorn

Joined: Feb 08, 2010
Posts: 23
Hi guys, I hav the following problem:
In my web service I do

InitialContext context = new InitialContext();
DataSource ds = (DataSource)context.lookup(jndiName);
where jndiName is = java:jdbc/SPChargingTransactionReportDataSource

from weblogic console I see:
Name = ChargingTransactionReport1-DS
JNDINAME= jdbc/SPChargingTransactionReportDataSource

so apparently I have a correct binding...

still, I get NamingException....
any idea why? am I supposed to prefix jndiName with java: like I am doing in java code?

Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Not necessary. But where exactly is the name being bound ? Did you look under the view JNDI tree option to see the object ? That will tell you the exact name


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Luca Zitto
Greenhorn

Joined: Feb 08, 2010
Posts: 23
Well, problem is that i do not have access to weblogic, so I did my tests on jboss... and all worked
I have now delivered the ear to a collegue who has access to weblogic and he's getting this error.

he sent me a screenshot of the datasource configuration in weblogic and as I said below the jndiname is the same, except in java code I prefix it with java:
Luca Zitto
Greenhorn

Joined: Feb 08, 2010
Posts: 23
I removed the java: from my code and it works... although i don't like the fact that this makes it less portable...
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Probably a container specific problem ? Where did you define the resource ? Containers may choose to bind it into the JNDI based on their own standards.

Well atleast you know why it does not work now
Luca Zitto
Greenhorn

Joined: Feb 08, 2010
Posts: 23
I guess it is a container (i.e. weblogic) specific issue... Where did I define the resource... not 100% sure I understand the question... I mean, normally I deploy on jboss, and all you have to do on jboss is:
create a datasource file
specifiy a jndiname in the datasource file

and that's it, the datasource is ready to be used by any application running on the server. In java code you prefix the jndiname with java:

For weblogic, which I do not have available but where my code is now installed (by other guys), I had to request that a datasource was created via the GUI, using same jndiname I used on jboss.
In my code I had to remove the java: prefix.
I am not sure if when defining a datasource in weblogic I needed to do anything else? maybe map it in web.xml, weblogic.xml or other?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Mentioning a resource ref in web.xml usually allows the container to map the object in the JNDI. How it maps it in the JNDI is container specific.

It is still possible to use the java: prefix in other container provided there is no clash in the namespace
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NamingException when trying to get a datasource