• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

datasource jndi cast error

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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[]){
try{
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/ds1");
System.out.println("Finished");
}catch(Exception e){
e.printStackTrace();
}
}
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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic