File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Websphere and the fly likes datasource jndi cast error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "datasource jndi cast error" Watch "datasource jndi cast error" New topic

datasource jndi cast error

Joseph Siao
Ranch Hand

Joined: Feb 26, 2004
Posts: 32
I need help. I am using websphere 5, and MySQL as my database. I created a datasource in my websphere server test environment. I create a simple java application to lookup the datasource.
Here is my code :
public static void main(String arg[]){
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/ds1");
}catch(Exception e){
An error is occuring on DataSource cast. I dont know why..
Here is the error :
java.lang.ClassCastException: javax.naming.Reference
at ds.test.DsTestMain.main(
Hope someone can help me.
Manish Pawar

Joined: Apr 14, 2004
Posts: 6
There are two possible reasons for above, which i cn think of at present..
- either the lookup is not happening.
For this run - (WAS_Install_Root)/AppServer/bin/dumpNameSpace - to check whether the name -"jdbc/ds1" exist or not. If it doesn't, the name has not yet been 'configured' yet since u hv created the datasource. Check the configurations for datasource, if they are all right, restart the websphere for changes to take effect.
- or the casting is improper.

One possible solution is to narrow down the object first and then use casting. (Use PortableRemoteObject.narrow )
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi ajsc ,
Welcome to JavaRanch, the absolute best site on the www for Java information. We don't have many rules around here, but we do have one. Please change your display name to a first and last name to comply with the JavaRanch Naming Policy. You can change it here. Thank you for your cooperation.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: datasource jndi cast error
It's not a secret anymore!