• 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

DataSource InitialContext vs Class.for  RSS feed

 
Ranch Hand
Posts: 144
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is based on Wildfly 10.1 Standalone and Derby Remote client. I assume the same will be true for other environments.

I have deployed derbyclient.jar to the deployments folder and registered a DataSource in Wildfly named 'SimpleWebProjectDS', a JNDI-Name of 'java:jboss/SimpleWebProjectDS' and associated this with the deployed Derby driver. The server URL is set to 'jdbc:derby://localhost:1527/SimpleWebProjectDB;create=true'.

With Derby running on port 1527, the following causes a ClassNotFoundException:



The following executes without throwing an exception and produces the expected functionality:



Why does the first solution cause a ClassNotFoundError?
 
Bartender
Posts: 9496
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, can you show us how you configured JNDI?
 
Ashley Bye
Ranch Hand
Posts: 144
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In standalone.xml:

 
Ashley Bye
Ranch Hand
Posts: 144
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although in the configuration posted I've used a database named Employee rather than SimpleWebProject, which would lead to a revised connection URL from that given in the first post.
 
Stephan van Hulst
Bartender
Posts: 9496
184
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, the difference is that with JNDI, you specified the name of the driver JAR, so JNDI knows where to find the class. When you use Class.forName(), it will only work if derbyclient.jar is on your class path, which you probably forgot.
 
Ashley Bye
Ranch Hand
Posts: 144
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, so I still need to include it on the classpath even if deployed to an App Server?
 
Stephan van Hulst
Bartender
Posts: 9496
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on whether the application server has that particular driver on its class path.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!