Environment:
MySql: 5.6.17 and using mysql-connector-java-5.1.33-bin.jar
Tomcat: 7.0.56
Java: 6
Eclipse: Eclipse Java EE
IDE for Web Developers Version: Indigo Service Release 2
Mac OS X: 10.9.5
When I create a DataSource in Eclipse, I can successfully ping the database. However, when I try to use that DataSource programmatically, I get the attached StackTrace ( not allowed to attach StackTrace as it is in a .txt file). I will include a few lines here:
javax.naming.NameNotFoundException: Name [java.naming.InitialContext] is not bound in this Context. Unable to find [java.naming.InitialContext].
at org.apache.naming.NamingContext.list(NamingContext.java:370)
at org.apache.naming.NamingContext.list(NamingContext.java:394)
at org.apache.naming.SelectorContext.list(SelectorContext.java:352)
at javax.naming.InitialContext.list(InitialContext.java:436)
at com.schwartz.dao.MySql_Utils.MySqlConn(MySql_Utils.java:20)
at com.schwartz.customerProject.status.V1_status.returnDatabaseStatus(V1_status.java:38)
I have created and used a DataSource in Java code; that worked using the instructions at
http://theopentutorials.com/examples/java-ee/servlet/servlet-jndi-datasource-in-tomcat/.
Do I need to modify the context.xml to use this DataSource created with the wizard? I added a resource-ref to the web.xml although the tutorial I was following did not indicate that was necessary.
This is the tutorial I used to create the DataSource with the wizard provided by Eclipse:
http://theopentutorials.com/tutorials/eclipse/dtp/eclipse-dtp-configure-mysql-datasource-data-source-explorer/
---------------------------------------------------------------------------------------------------
Partial web.xml:
<
servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.schwartz.customerProject</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/customers/*</url-pattern>
</servlet-mapping>
<resource-ref>
<description>DB connection</description>
<res-ref-name>jdbc/customers</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
----------------------------------------------------------------------------
/WEB-INF/context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- The contents of this file will be loaded for each web application -->
<Context crossContext="true">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/customers" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/customers"/>
</Context>
Thank you for your time.