I'm receiving the following error in Eclipse. My instructor was supposed to help me with this but I haven't heard back from him. I'm wondering if anyone here would be familiar??
Here is the error.
Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
I'll post all the code below but I have a question about line 33 which is specified in the error.
Line 33 in the ConnectionPool class is and the dataSource variable value is
The above code is taken from the book I'm working in It works for others in my class but my Eclipse is setup differently. It's setup in the same way I was told to set it up for work.
Is by any chance this line java:/comp/env/jdbc has something to do with my java folder location? Currently my java is in C:\Development\Java\jdk1.8.0_71_64 . I have it setup to match my work computer setup. In the Environment variables of my computer I have JAVA_HOME set to C:\Development\Java\jdk1.8.0_71_64. I can't help but think maybe that's why I'm receiving this error? Maybe I need to change the value of the dataSource variable? I know that JDBC is Java Database Connectivity (JDBC) so I'm probably wrong regarding this but I can't think of any other reason why it's not working for me and it does others.
Thank You for your help.
The ConnectionPool class which contains line 33 referenced above. Following this is the class ( with the remaining lines being referenced) . Last is the context.xml file that I have and that file is in the META-INF folder.
I'm using MySQL
My database schemas include a database name Country , sys, and testdata but my instructor says that I don't need to specify these database in the context.xml file.
It looks like the issue you're running into revolves around the fact that your IntialContext object doesn't actually know where your context.xml file is. You declared it as a "new InitialContext()" on line 17 of your connection pool class, then on the next line told it to retrieve a DataSource, but it can't because it doesn't know where to find any datasources.
If your project is a Java Web project, the part where you tell your project where to find the context.xml file is usually handled for you, so I'm actually not sure how to tell it where to find one of those in a standard project, but I'm pretty sure the issue lies in the fact that your InitialContext object, while not null, does not actually know where it should be trying to find your context.xml file.
The InitialContext is configured as a web application is initially deployed, and is made available to web application components (for read-only access). All configured entries and resources are placed in the java:comp/env portion of the JNDI namespace, so a typical access to a resource - in this case, to a JDBC DataSource - would look something like this: