• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

datasource jndi cast error

Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(DsTestMain.java:37)
Hope someone can help me.
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 )
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Don't MAKE me come back there with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!