• Post Reply Bookmark Topic Watch Topic
  • New Topic

DataSource InitialContext vs Class.for  RSS feed

 
Ashley Bye
Ranch Hand
Posts: 140
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?
 
Stephan van Hulst
Saloon Keeper
Posts: 7932
143
  • 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: 140
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In standalone.xml:

 
Ashley Bye
Ranch Hand
Posts: 140
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
Saloon Keeper
Posts: 7932
143
  • 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: 140
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
Saloon Keeper
Posts: 7932
143
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!